From 518d13d5d3c591a564791455dd9314f2b002ae90 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 18 Apr 2024 11:17:33 +0000 Subject: [PATCH] Bug 36473: (follow-up) Additionally warn the stringified exception Signed-off-by: Katrin Fischer (cherry picked from commit 903a8685c661ddde61335a08e126506120345abc) Signed-off-by: Fridolin Somers (cherry picked from commit bc7842c649088ed94aeea13d59b683b25c720de9) Signed-off-by: Lucas Gass --- C4/Biblio.pm | 1 + t/db_dependent/Biblio.t | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 4c351a9e94..5d29b9d491 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -3038,6 +3038,7 @@ sub UpdateTotalIssues { if ($@) { my $exception = $@; $exception->rethrow unless ( $exception->isa('Koha::Exceptions::Metadata::Invalid') ); + warn $exception; warn "UpdateTotalIssues could not get bibliographic record for biblionumber $biblionumber"; return; } diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t index c920d2a392..e8813b78cd 100755 --- a/t/db_dependent/Biblio.t +++ b/t/db_dependent/Biblio.t @@ -1026,18 +1026,32 @@ subtest 'UpdateTotalIssues on Invalid record' => sub { plan tests => 2; my $return_record = Test::MockModule->new('Koha::Biblio::Metadata'); - $return_record->mock( 'record', sub { Koha::Exceptions::Metadata::Invalid->throw() } ); + $return_record->mock( 'record', sub { + my $self = shift; + Koha::Exceptions::Metadata::Invalid->throw( + id => $self->id, + biblionumber => $self->biblionumber, + format => $self->format, + schema => $self->schema, + decoding_error => "Error goes here", + ); + } ); - my $biblio = $builder->build_sample_biblio; - my $biblionumber = $biblio->biblionumber; + my $biblio = $builder->build_sample_biblio; + my $biblionumber = $biblio->biblionumber; + my $biblio_metadata_id = $biblio->metadata->id; my $increase = 1; my $success; - warning_is { + warnings_like { $success = C4::Biblio::UpdateTotalIssues( $biblio->biblionumber, $increase, '' ); } - "UpdateTotalIssues could not get bibliographic record for biblionumber $biblionumber", "Expected warning found"; + [ + qr/Invalid data, cannot decode metadata object/, + qr/UpdateTotalIssues could not get bibliographic record for biblionumber $biblionumber/ + ], + "Expected warning found"; ok( !$success, 'UpdateTotalIssues fails gracefully for invalid record' ); -- 2.39.5