diff --git a/C4/Matcher.pm b/C4/Matcher.pm index 0aaaf818d9..35ba08af79 100644 --- a/C4/Matcher.pm +++ b/C4/Matcher.pm @@ -752,8 +752,16 @@ sub get_matches { my ( $authresults, $total ) = $searcher->search_auth_compat( $search_query, 0, 20 ); foreach my $result (@$authresults) { - my $id = $result->{authid}; - my $target_record = Koha::Authorities->find($id)->record; + my $id = $result->{authid}; + my $target_auth = Koha::Authorities->find($id); + my $target_record = eval { $target_auth->record }; + my $invalid_record = $@ || !$target_record; + if ($invalid_record) { + warn + "Error parsing matched authority record $id, attempting to clean record, record will be skipped if it fails"; + $target_record = $target_auth->record_strip_nonxml; + } + next unless $target_record; $matches->{$id}->{score} += $matchpoint->{'score'}; $matches->{$id}->{record} = $target_record; }