From e1c8f79b8f69a3c60dd2c47eed44a7a5c5186b47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadeusz=20=E2=80=9Etadzik=E2=80=9D=20So=C5=9Bnierz?= Date: Fri, 23 Jan 2026 14:34:40 +0100 Subject: [PATCH] Bug 41694: Ensure Koha::Exception::Object's full_message() always produces one --- Koha/Exceptions/Object.pm | 4 ++++ t/Koha/Exceptions.t | 29 ++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Koha/Exceptions/Object.pm b/Koha/Exceptions/Object.pm index 85181d9f90..57aa4c8bc3 100644 --- a/Koha/Exceptions/Object.pm +++ b/Koha/Exceptions/Object.pm @@ -92,6 +92,10 @@ sub full_message { } } + if ( !$msg ) { + return $self->SUPER::full_message; + } + return $msg; } diff --git a/t/Koha/Exceptions.t b/t/Koha/Exceptions.t index 0f12bc2e7d..3cd6f02c56 100755 --- a/t/Koha/Exceptions.t +++ b/t/Koha/Exceptions.t @@ -18,7 +18,7 @@ use Modern::Perl; use Test::NoWarnings; -use Test::More tests => 13; +use Test::More tests => 14; use Test::MockObject; use Test::Exception; @@ -427,3 +427,30 @@ subtest 'Passing parameters when throwing exception' => sub { like( $desc, qr/type => ARRAY/, 'Found type' ); like( $desc, qr/value => ARRAY\(\w+\)/, 'Found value' ); }; + +subtest 'full_message() should provide all the details' => sub { + plan tests => 6; + + use Koha::Exceptions::Object; + + throws_ok { + Koha::Exceptions::Object::DuplicateID->throw( + duplicate_id => 'test_id', + message => 'the message', + ); + } + 'Koha::Exceptions::Object::DuplicateID'; + + like( $@->full_message, qr/the message/, 'Found the message' ); + unlike( $@->full_message, qr/test_id/, 'The message hides the original details' ); + + throws_ok { + Koha::Exceptions::Object::DuplicateID->throw( + duplicate_id => 'test_id', + ); + } + 'Koha::Exceptions::Object::DuplicateID'; + + like( $@->full_message, qr/DuplicateID/, 'Found exception type' ); + like( $@->full_message, qr/test_id/, 'The message hides the original details' ); +}; -- 2.51.0