From bff655bcb7325f534bf32b8220eefe9ee5ca0f55 Mon Sep 17 00:00:00 2001 From: Bernardo Gonzalez Kriegel Date: Fri, 20 May 2016 14:26:14 -0300 Subject: [PATCH] Bug 13669: Re-adds error handling to load_sql This patch prevents crashing in case an error is detected when loading a file To test: 1) Apply patch 2) Mangle kohastructure.sql or any sample file adding and invalid SQL line 3) Run webinstaller and check that the error is handled gracefully Signed-off-by: Jonathan Druart --- C4/Installer.pm | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/C4/Installer.pm b/C4/Installer.pm index 54587de..9ffc396 100644 --- a/C4/Installer.pm +++ b/C4/Installer.pm @@ -428,18 +428,24 @@ with missing files, e.g. =cut sub load_sql { - my $self = shift; my $filename = shift; + my $error; my $dbh = $self->{ dbh }; - my $error = DBIx::RunSQL->run_sql_file( - dbh => $dbh, - sql => $filename, - ); - - $error = ( $error ) ? "ERROR: $filename" : ""; + eval { + DBIx::RunSQL->run_sql_file( + dbh => $dbh, + sql => $filename, + ); + }; + # errors thrown while loading installer data should be logged + if( $@ ) { + warn "C4::Installer::load_sql returned the following errors while attempting to load $filename:\n"; + warn "$@"; + $error = "Error attempting to load $filename:\n$@"; + } return $error; } -- 2.8.1