From 054ee5bd09a6f42076112f6dbf451206d53ff698 Mon Sep 17 00:00:00 2001 From: Casper Date: Sun, 26 Sep 2021 10:37:50 +0200 Subject: [PATCH] Update "error tracing" doc (#2216) --- docs/content/contributing/coding-style.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/content/contributing/coding-style.md b/docs/content/contributing/coding-style.md index bc13d177..cad6048a 100644 --- a/docs/content/contributing/coding-style.md +++ b/docs/content/contributing/coding-style.md @@ -87,17 +87,20 @@ A construct to trace error in your scripts looks like this. Remember: Remove `se ```bash set -xeuEo pipefail -trap '__log_err ${FUNCNAME[0]:-"?"} ${BASH_COMMAND:-"?"} ${LINENO:-"?"} ${?:-"?"}' ERR +trap '__err "${BASH_SOURCE}" "${FUNCNAME[0]:-?}" "${BASH_COMMAND:-?}" "${LINENO:-?}" "${?:-?}"' ERR -SCRIPT='name_of_this_script.sh' - -function __log_err +function __err { - printf "\n--- \e[1m\e[31mUNCHECKED ERROR\e[0m\n%s\n%s\n%s\n%s\n\n" \ - " - script = ${SCRIPT:-${0}}" \ - " - function = ${1} / ${2}" \ - " - line = ${3}" \ - " - exit code = ${4}" 1>&2 + local RED="\e[31m\e[1m" + local RESET="\e[0m" + local ERR_MSG="\n--- ${RED}UNCHECKED ERROR${RESET}" + ERR_MSG+="\n - script = ${1}" + ERR_MSG+="\n - function = ${2}" + ERR_MSG+="\n - command = ${3}" + ERR_MSG+="\n - line = ${4}" + ERR_MSG+="\n - exit code = ${5}" + + echo -e "${ERR_MSG}" }