Skip to content

Commit

Permalink
Adds exit code of failed command to the call stack (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkakouros authored and niieani committed Jan 19, 2018
1 parent 08657e3 commit 505d7eb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/util/exception.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import String/GetSpaces String/SlashReplacement UI/Color UI/Console
### HANDLE EXCEPTIONS ###
#########################

trap "__EXCEPTION_TYPE__=\"\$_\" command_not_found_handle \$BASH_COMMAND" ERR
trap "__EXCEPTION_TYPE__=\"\$_\" command_not_found_handle \$? \$BASH_COMMAND" ERR
set -o errtrace # trace ERR through 'time command' and other functions

# unalias throw 2> /dev/null || true
Expand Down Expand Up @@ -37,6 +37,8 @@ command_not_found_handle() {

Exception::CustomCommandHandler "$@" && return 0 || true

local exit_code="${1}"
shift
local script="${BASH_SOURCE[1]#./}"
local lineNo="${BASH_LINENO[0]}"
local undefinedObject="$*"
Expand Down Expand Up @@ -83,7 +85,7 @@ command_not_found_handle() {
Exception::FillExceptionWithTraceElements

Console::WriteStdErr
Console::WriteStdErr " $(UI.Color.Red)$(UI.Powerline.Fail) $(UI.Color.Bold)UNCAUGHT EXCEPTION: $(UI.Color.LightRed)${type}$(UI.Color.Default)"
Console::WriteStdErr " $(UI.Color.Red)$(UI.Powerline.Fail) $(UI.Color.Bold)UNCAUGHT EXCEPTION: $(UI.Color.LightRed)${type} $(UI.Color.Yellow)$(UI.Color.Italics)(${exit_code})$(UI.Color.Default)"
Exception::PrintException "${exception[@]}"

Exception::ContinueOrBreak
Expand Down

0 comments on commit 505d7eb

Please sign in to comment.