Skip to content

Instantly share code, notes, and snippets.

@cardil
Last active October 12, 2022 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cardil/810d5471c6617c4391d7f4fe07670f74 to your computer and use it in GitHub Desktop.
Save cardil/810d5471c6617c4391d7f4fe07670f74 to your computer and use it in GitHub Desktop.
Bash scripting pitfall
#!/usr/bin/env bash
set -Eeuo pipefail
function error_handler() {
local code="${1:-${?}}"
abort "🚨 Error (code: ${code}) occurred at ${BASH_SOURCE[1]}:${BASH_LINENO[0]}, with command: ${BASH_COMMAND}"
}
function abort() {
echo "Error: $*" >&2
exit 42
}
function sign() {
echo 'Signing'
false
echo 'Signed'
}
function main() {
trap error_handler ERR
sign || abort "Failed to sign"
# sign
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment