From 903a8685c661ddde61335a08e126506120345abc 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 --- 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 170e9f9cd9..d9e43b7dba 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -3062,6 +3062,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