From 3d643082ca017048deedbc37e991ef695f940f43 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 24 Feb 2025 17:35:13 +0000 Subject: [PATCH] Bug 39191: Add `format` parameter to Koha::Exceptions::ArticleRequest::WrongFormat This patch just adds a new parameter so any exception consumer or even the logs contain more information about the context in which the exception was thrown. This would be useful debugging issues. No behavior change in Koha. To test: 1. Run: $ ktd --shell k$ prove t/db_dependent/Koha/ArticleRequest.t => SUCCESS: Tests pass! 2. Apply this patch 3. Repeat 2 => SUCCESS: Tests pass! 4. Sign off :-D Signed-off-by: Martin Renvoize --- Koha/ArticleRequest.pm | 2 +- Koha/Exceptions/ArticleRequest.pm | 3 ++- t/db_dependent/Koha/ArticleRequest.t | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Koha/ArticleRequest.pm b/Koha/ArticleRequest.pm index 33421fbb3a1..f1d5968754f 100644 --- a/Koha/ArticleRequest.pm +++ b/Koha/ArticleRequest.pm @@ -269,7 +269,7 @@ sub store { $self->created_on( dt_from_string() ); } - Koha::Exceptions::ArticleRequest::WrongFormat->throw + Koha::Exceptions::ArticleRequest::WrongFormat->throw( format => $self->format ) unless grep { $_ eq $self->format } @{ C4::Context->multivalue_preference('ArticleRequestsSupportedFormats') }; return $self->SUPER::store; diff --git a/Koha/Exceptions/ArticleRequest.pm b/Koha/Exceptions/ArticleRequest.pm index 9e016a6f7e1..ad46187a411 100644 --- a/Koha/Exceptions/ArticleRequest.pm +++ b/Koha/Exceptions/ArticleRequest.pm @@ -29,7 +29,8 @@ use Exception::Class ( }, 'Koha::Exceptions::ArticleRequest::WrongFormat' => { isa => 'Koha::Exceptions::ArticleRequest', - description => 'Passed format is not locally supported' + description => 'Passed format is not locally supported', + fields => ['format'], }, ); diff --git a/t/db_dependent/Koha/ArticleRequest.t b/t/db_dependent/Koha/ArticleRequest.t index 586fb1c755c..6fa2a4b4654 100755 --- a/t/db_dependent/Koha/ArticleRequest.t +++ b/t/db_dependent/Koha/ArticleRequest.t @@ -224,13 +224,14 @@ subtest 'cancel() tests' => sub { }; subtest 'store' => sub { - plan tests => 2; + plan tests => 3; $schema->storage->txn_begin; t::lib::Mocks::mock_preference( 'ArticleRequestsSupportedFormats', 'SCAN' ); my $ar = $builder->build_object( { class => 'Koha::ArticleRequests', value => { format => 'PHOTOCOPY' } } ); throws_ok { $ar->format('test')->store } 'Koha::Exceptions::ArticleRequest::WrongFormat', 'Format not supported'; + is( $@->format, 'test', 'Passed format returned with the exception' ); t::lib::Mocks::mock_preference( 'ArticleRequestsSupportedFormats', 'SCAN|PHOTOCOPY|ELSE' ); lives_ok { $ar->format('PHOTOCOPY')->store } 'Now we do support it'; -- 2.49.0