From ca814a4e6fe72e9dcf101e2d0a49623304e488b5 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Tue, 3 Jan 2023 18:25:50 -0800 Subject: [PATCH] If we get an ERROR output when executing an SQL file, consider it failed even if the exit status is zero --- mysql/mysql-lib.pl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mysql/mysql-lib.pl b/mysql/mysql-lib.pl index 6104af330..01d8d4f74 100755 --- a/mysql/mysql-lib.pl +++ b/mysql/mysql-lib.pl @@ -1036,7 +1036,19 @@ if ($_[4] && $_[4] ne 'root' && $< == 0) { $cmd = &command_as_user($_[4], 0, $cmd); } local $out = &backquote_logged("$cmd 2>&1"); -local @rv = ($?, $? ? $out || "$cmd failed" : $out); +local @rv; +if ($?) { + # Total failure + @rv = ($?, $out || "$cmd failed"); + } +elsif ($out =~ /(^|\n)(ERROR\s+\d+.*)/) { + # Some command in the file failed + @rv = (1, $2); + } +else { + # All OK + @rv = (0, $out); + } &make_authstr(); # Put back old password environment variable return @rv; }