Skip to content

Commit 46f6e8c

Browse files
authored
Merge pull request #65 from KevinCarterDev/proper_exit_code
Return a proper exit code if an error occurs
2 parents 65fceaf + 6b27472 commit 46f6e8c

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

pg_sample

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ $SIG{TERM} = $SIG{INT} = $SIG{QUIT} = $SIG{HUP} = sub {
211211
die "Received signal '$signal'; cleaning up and terminating.\n";
212212
};
213213

214+
$SIG{__DIE__} = sub { our @reason = @_ };
215+
214216
BEGIN {
215217
# Encapsulate a fully-qualified Postgresql table name
216218
package Table;
@@ -943,12 +945,18 @@ foreach my $table (@tables) {
943945
print "\n";
944946

945947
END {
948+
our @reason;
949+
946950
# remove sample tables unless requested not to
947951
if ($created_schema && !$opt{keep}) {
948952
notice "Dropping sample schema $opt{sample_schema}\n";
949953
$dbh->do("DROP SCHEMA $opt{sample_schema} CASCADE");
950954
}
951955

952956
notice "Done.\n";
953-
exit 0;
957+
if (@reason) {
958+
exit 1;
959+
} else {
960+
exit 0;
961+
}
954962
}

0 commit comments

Comments
 (0)