From 7b30d9efebf97f4905aab14ed54b47a3d4c37a7d Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Wed, 19 Feb 2025 19:29:18 +0100 Subject: [PATCH] Bug 20551: Get biblionumber safly in validator function --- Koha/Exporter/Record.pm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Koha/Exporter/Record.pm b/Koha/Exporter/Record.pm index 0b3f002ecc7..645d79572f6 100644 --- a/Koha/Exporter/Record.pm +++ b/Koha/Exporter/Record.pm @@ -257,10 +257,18 @@ sub export { if ( $format eq 'iso2709' ) { my $encoding_validator = sub { my ( $record, $record_type ) = @_; - my $errorcount_on_decode = - eval { scalar( MARC::File::USMARC->decode( $record->as_usmarc )->warnings() ) }; - if ( $errorcount_on_decode || $@ ) { - my $msg = "$record_type could not be USMARC decoded/encoded. " . ( $@ // '' ); + my @decoding_warnings = + eval { MARC::File::USMARC->decode( $record->as_usmarc )->warnings() }; + my $error = $@; + if ( $error || @decoding_warnings ) { + my ( $id_tag, $id_code ) = GetMarcFromKohaField( 'biblio.biblionumber', '' ); + my $field = $record->field($id_tag); + my $msg = "$record_type"; + if ($field) { + $msg .= " " . $field->is_control_field ? $field->data : $field->subfield($id_code); + } + my $warnings = join(', ', @decoding_warnings); + $msg .= " could not be USMARC decoded/encoded. " . ( $error // $warnings ); chomp $msg; Koha::Logger->get->warn($msg); return 0; -- 2.48.1