Bug 36942: Use an exception for a failed KBART file parse

Test plan:
1) prove t/db_dependent/Koha/BackgroundJob/ImportKBARTFile.t

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Matt Blenkinsop 2024-07-03 11:17:27 +00:00 committed by Lucas Gass
parent 41e198bfcd
commit a869b7297f
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
3 changed files with 9 additions and 6 deletions

View File

@ -136,8 +136,7 @@ sub read_file {
unless ( $csv->eof() ) {
my ( $cde, $str, $pos ) = $csv->error_diag();
my $error = $cde ? "$cde, $str, $pos" : "";
warn $error if $error;
return ( $column_headers, $lines, $error );
Koha::Exceptions::FileNotParsed->throw( filename => $file->{filename}, error => $error );
}
return ( $column_headers, $lines, '' );

View File

@ -20,6 +20,11 @@ use Exception::Class (
description => 'File not found',
fields => ['filename'],
},
'Koha::Exceptions::FileNotParsed' => {
isa => 'Koha::Exception',
description => 'File could not be parsed',
fields => [ 'filename', 'error' ],
},
'Koha::Exceptions::InvalidStatus' => {
isa => 'Koha::Exception',
description => 'The current status is not valid in context',

View File

@ -21,6 +21,7 @@ use Test::NoWarnings;
use Test::More tests => 9;
use Test::MockModule;
use Test::Warn;
use Test::Exception;
use Koha::Database;
use Koha::BackgroundJobs;
@ -136,10 +137,8 @@ Nature Plants,,2055-0278,2015-01,1,1,,,,https://www.nature.com/nplants,,4aaa7,,f
Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bbb0,,fulltext,Hybrid (Open Choice),Nature Publishing Group UK,serial,,,,,,,,P"
)
};
warning_is {
Koha::ERM::EHoldings::Title::read_file($file2);
}
'2023, EIQ - QUO character not allowed, 157', 'Error message correctly reported';
throws_ok { Koha::ERM::EHoldings::Title::read_file($file2); } 'Koha::Exceptions::FileNotParsed';
};
subtest '_create_title_hash_from_line_data' => sub {