From 17df0775edaf1d45c59a41147779fd65fd986911 Mon Sep 17 00:00:00 2001 From: Kui Shi Date: Fri, 2 Aug 2013 17:55:41 +0800 Subject: [PATCH] misleading source filename in error message when ./stack.sh encounters error, the output may look like this: [ERROR] ./stack.sh:698 nova-api did not start The source filename is wrong. Actually, it should be like this: [ERROR] //lib/nova:698 nova-api did not start stack.sh uses bash as interpreter, which define "Shell Variables" BASH_SOURCE: An array variable whose members are the source filenames where the corresponding shell function names in the FUNCNAME array variable are defined. The shell function ${FUNCNAME[$i]} is defined in the file ${BASH_SOURCE[$i]} and called from ${BASH_SOURCE[$i+1]}. The function "err" is called by function "die" ( and "err_if_not_set", and "err_if_not_set" is not used at all). ${BASH_SOURCE[2]} will ignore the deepest two call entries, which corresponding to the shell functions: "err" and "die". In one sentence, this change will print the source filename where the function is defined and exits via function "die". Fixes bug #1207658 Change-Id: I2aa6642c5cf4cfe781afe278b3dec3e7cba277fa --- functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions b/functions index 262f70f29f..43ff1a7731 100644 --- a/functions +++ b/functions @@ -113,7 +113,7 @@ function err() { local exitcode=$? errXTRACE=$(set +o | grep xtrace) set +o xtrace - local msg="[ERROR] $0:$1 $2" + local msg="[ERROR] ${BASH_SOURCE[2]}:$1 $2" echo $msg 1>&2; if [[ -n ${SCREEN_LOGDIR} ]]; then echo $msg >> "${SCREEN_LOGDIR}/error.log"