mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
Update "error tracing" doc (#2216)
This commit is contained in:
parent
23b8523ee3
commit
054ee5bd09
|
@ -87,17 +87,20 @@ A construct to trace error in your scripts looks like this. Remember: Remove `se
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
set -xeuEo pipefail
|
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 __err
|
||||||
|
|
||||||
function __log_err
|
|
||||||
{
|
{
|
||||||
printf "\n--- \e[1m\e[31mUNCHECKED ERROR\e[0m\n%s\n%s\n%s\n%s\n\n" \
|
local RED="\e[31m\e[1m"
|
||||||
" - script = ${SCRIPT:-${0}}" \
|
local RESET="\e[0m"
|
||||||
" - function = ${1} / ${2}" \
|
local ERR_MSG="\n--- ${RED}UNCHECKED ERROR${RESET}"
|
||||||
" - line = ${3}" \
|
ERR_MSG+="\n - script = ${1}"
|
||||||
" - exit code = ${4}" 1>&2
|
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}"
|
||||||
|
|
||||||
<CODE TO RUN AFTERWARDS>
|
<CODE TO RUN AFTERWARDS>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue