File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -274,10 +274,32 @@ core.err_exists() {
274274core.stacktrace_print () {
275275 printf ' %s\n' ' Stacktrace:'
276276
277+ local old_cd=" $PWD " cd_failed=' no'
277278 local i=
278279 for (( i= 0 ; i< ${# FUNCNAME[@]} - 1 ; ++ i)) ; do
279- printf ' %s\n' " in ${FUNCNAME[$i]} (${BASH_SOURCE[$i]} :${BASH_LINENO[$i-1]} )"
280+ local file=" ${BASH_SOURCE[$i]} "
281+
282+ # If the 'cd' has previous failed, then do not attempt to 'cd' as the current
283+ # directory is not in '$old_cd' (so the 'cd' will almost certainly fail)
284+ if [ " $cd_failed " = ' no' ]; then
285+ # shellcheck disable=SC1007
286+ if CDPATH= cd -- " ${file%/* } " ; then
287+ file=" $PWD /${file##*/ } "
288+ else
289+ cd_failed=' yes'
290+ fi
291+ fi
292+
293+ printf ' %s\n' " in ${FUNCNAME[$i]} ($file :${BASH_LINENO[$i-1]} )"
294+
295+ if ! CDPATH= cd -- " $old_cd " ; then
296+ cd_failed=' yes'
297+ fi
280298 done ; unset -v i
299+
300+ if [ " $cd_failed " = ' yes' ]; then
301+ printf ' %s\n' " Error: bash-error: A 'cd' failed, so the stacktrace may include relative paths"
302+ fi
281303} >&2
282304
283305# @description Determine if color should be printed
You can’t perform that action at this time.
0 commit comments