Skip to content

Commit

Permalink
{bare-minimum,basic}: fix: Fix program not able to report unhandled e…
Browse files Browse the repository at this point in the history
…rrors

Fixes #3.

Signed-off-by: 林博仁(Buo-ren, Lin) <[email protected]>
  • Loading branch information
brlin-tw committed Mar 23, 2024
1 parent 602b0f6 commit da5d118
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bare-minimum.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,14 @@ if ! set "${set_opts[@]}"; then
exit 1
fi

printf \
'Info: Setting the ERR trap...\n'
if ! trap 'printf "Error: The program has encountered an unhandled error and is prematurely aborted.\\n" 1>&2' ERR; then
printf \
'Error: Unable to set the ERR trap.\n' \
1>&2
exit 1
fi

printf \
'Info: Operation completed without errors.\n'
9 changes: 9 additions & 0 deletions basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,14 @@ fi
script_args=("${@}")
}

printf \
'Info: Setting the ERR trap...\n'
if ! trap trap_err ERR; then
printf \
'Error: Unable to set the ERR trap.\n' \
1>&2
exit 1
fi

printf \
'Info: Operation completed without errors.\n'

0 comments on commit da5d118

Please sign in to comment.