From 6b27472f24e089ebb7af0813dfeec2acfecf0cec Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Tue, 25 Mar 2025 15:30:09 -0600 Subject: [PATCH] Return a proper exit code if an error occurs --- pg_sample | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pg_sample b/pg_sample index 603d103..400d5dd 100755 --- a/pg_sample +++ b/pg_sample @@ -211,6 +211,8 @@ $SIG{TERM} = $SIG{INT} = $SIG{QUIT} = $SIG{HUP} = sub { die "Received signal '$signal'; cleaning up and terminating.\n"; }; +$SIG{__DIE__} = sub { our @reason = @_ }; + BEGIN { # Encapsulate a fully-qualified Postgresql table name package Table; @@ -943,6 +945,8 @@ foreach my $table (@tables) { print "\n"; END { + our @reason; + # remove sample tables unless requested not to if ($created_schema && !$opt{keep}) { notice "Dropping sample schema $opt{sample_schema}\n"; @@ -950,5 +954,9 @@ END { } notice "Done.\n"; - exit 0; + if (@reason) { + exit 1; + } else { + exit 0; + } }