niieani / bash-oo-framework

Bash Infinity is a modern standard library / framework / boilerplate for Bash
https://github.com/niieani/bash-oo-framework/discussions
MIT License
5.57k stars 247 forks source link

error handling with throw / command_not_found_handle #107

Closed rogard closed 6 months ago

rogard commented 6 months ago

Under the section in the title one reads:

"You may also force an error by throwing your own Exception:" e="The hard disk is not connected properly!" throw

Is there really supposed to be no ; between the two instructions? Executing it outputs several blank lines whereas I expected a "call stack". I don't know how to interpret the trace from set -x.

Please provide some troubleshooting guidance.

tangled.sh

#!/usr/bin/env bash

## BOOTSTRAP ##
g__oo='/home/erwann/github/bash-oo-framework'
source "$g__oo"/lib/oo-bootstrap.sh
# source "$( cd "${BASH_SOURCE[0]%/*}" && pwd )/../../lib/oo-bootstrap.sh"

## import ##

import /util/exception

## function ##

foo ()
{
    e="dummy error" throw
}

## exec ##

foo

Terminal:

$ uname -a        
Linux elitebook 6.8.4-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 05 Apr 2024 00:14:23 +0000 x86_64 GNU/Linux
$ exec env -i bash 
$ set -x; source tangled.sh 2> ~/Desktop/log
+ source tangled.sh

Excerpt from ~/Desktop/log

++++(oo-bootstrap.sh:138): System::SourceFile(): return 0
+++(exception.sh:8): source(): trap '__EXCEPTION_TYPE__="$_" command_not_found_handle $? $BASH_COMMAND' ERR
+++(exception.sh:9): source(): set -o errtrace
+++(exception.sh:12): source(): unset -f throw
+++(exception.sh:13): source(): alias 'throw=__EXCEPTION_TYPE__=${e:-Manually invoked} command_not_found_handle'
++(tangled.sh:21): foo
++(tangled.sh:16): foo(): e='dummy error'
++(tangled.sh:16): foo(): __EXCEPTION_TYPE__='dummy error'
++(tangled.sh:16): foo(): command_not_found_handle
++(exception.sh:30): command_not_found_handle(): local 'IFS=    
'
++(exception.sh:33): command_not_found_handle(): [[ '' = \(\ \s\e\t\ \-*\;\ \t\r\u\e* ]]
++(exception.sh:38): command_not_found_handle(): Exception::CustomCommandHandler
++(exception.sh:17): Exception::CustomCommandHandler(): return 1
++(exception.sh:38): command_not_found_handle(): true
++(exception.sh:40): command_not_found_handle(): local exit_code=
++(exception.sh:41): command_not_found_handle(): shift
++(exception.sh:41): command_not_found_handle(): true
++(exception.sh:42): command_not_found_handle(): local script=tangled.sh
++(exception.sh:43): command_not_found_handle(): local lineNo=16
++(exception.sh:44): command_not_found_handle(): local undefinedObject=
++(exception.sh:45): command_not_found_handle(): local 'type=dummy error'
++(exception.sh:47): command_not_found_handle(): [[ '' == \(*\) ]]
++(exception.sh:52): command_not_found_handle(): [[ -z '' ]]
++(exception.sh:54): command_not_found_handle(): undefinedObject='dummy error'
++(exception.sh:57): command_not_found_handle(): [[ '' -gt 0 ]]
++(exception.sh:77): command_not_found_handle(): [[ 0 -ge 25 ]]
++(exception.sh:83): command_not_found_handle(): exception=('16' 'dummy error' 'tangled.sh')
++(exception.sh:83): command_not_found_handle(): local -a exception
++(exception.sh:85): command_not_found_handle(): Exception::FillExceptionWithTraceElements
++(exception.sh:21): Exception::FillExceptionWithTraceElements(): local 'IFS=
'
+++(exception.sh:22): Exception::FillExceptionWithTraceElements(): Exception::DumpBacktrace 3
+++(exception.sh:241): Exception::DumpBacktrace(): local -i startFrom=3
+++(exception.sh:246): Exception::DumpBacktrace(): local 'IFS=  
'
+++(exception.sh:248): Exception::DumpBacktrace(): local -i i=0
+++(exception.sh:250): Exception::DumpBacktrace(): caller 0
+++(exception.sh:252): Exception::DumpBacktrace(): ((  0 + 1 >= 3  ))
+++(exception.sh:260): Exception::DumpBacktrace(): i+=1
+++(exception.sh:250): Exception::DumpBacktrace(): caller 1
+++(exception.sh:252): Exception::DumpBacktrace(): ((  1 + 1 >= 3  ))
+++(exception.sh:260): Exception::DumpBacktrace(): i+=1
+++(exception.sh:250): Exception::DumpBacktrace(): caller 2
+++(exception.sh:252): Exception::DumpBacktrace(): ((  2 + 1 >= 3  ))
++++(exception.sh:254): Exception::DumpBacktrace(): caller 2
+++(exception.sh:254): Exception::DumpBacktrace(): trace=('16' 'foo' 'tangled.sh')
+++(exception.sh:254): Exception::DumpBacktrace(): local -a trace
+++(exception.sh:256): Exception::DumpBacktrace(): echo 16
+++(exception.sh:257): Exception::DumpBacktrace(): echo foo
+++(exception.sh:258): Exception::DumpBacktrace(): echo tangled.sh
+++(exception.sh:260): Exception::DumpBacktrace(): i+=1
+++(exception.sh:250): Exception::DumpBacktrace(): caller 3
+++(exception.sh:252): Exception::DumpBacktrace(): ((  3 + 1 >= 3  ))
++++(exception.sh:254): Exception::DumpBacktrace(): caller 3
+++(exception.sh:254): Exception::DumpBacktrace(): trace=('21' 'source' 'tangled.sh')
+++(exception.sh:254): Exception::DumpBacktrace(): local -a trace
+++(exception.sh:256): Exception::DumpBacktrace(): echo 21
+++(exception.sh:257): Exception::DumpBacktrace(): echo source
+++(exception.sh:258): Exception::DumpBacktrace(): echo tangled.sh
+++(exception.sh:260): Exception::DumpBacktrace(): i+=1
+++(exception.sh:250): Exception::DumpBacktrace(): caller 4
++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++(exception.sh:87): command_not_found_handle(): Console::WriteStdErr
++(Console.sh:5): Console::WriteStdErr(): cat

++(Console.sh:6): Console::WriteStdErr(): return
+++(exception.sh:88): command_not_found_handle(): echo
+++(exception.sh:88): command_not_found_handle(): echo x
+++(exception.sh:88): command_not_found_handle(): echo
+++(exception.sh:88): command_not_found_handle(): echo
+++(exception.sh:88): command_not_found_handle(): echo
+++(exception.sh:88): command_not_found_handle(): UI.Color.Italics
+++(exception.sh:30): command_not_found_handle(): local 'IFS=   
'
+++(exception.sh:33): command_not_found_handle(): [[ UI.Color.Italics = \(\ \s\e\t\ \-*\;\ \t\r\u\e* ]]
+++(exception.sh:38): command_not_found_handle(): Exception::CustomCommandHandler UI.Color.Italics
+++(exception.sh:17): Exception::CustomCommandHandler(): return 1
+++(exception.sh:38): command_not_found_handle(): true
+++(exception.sh:40): command_not_found_handle(): local exit_code=UI.Color.Italics
+++(exception.sh:41): command_not_found_handle(): shift
+++(exception.sh:42): command_not_found_handle(): local script=/home/erwann/github/bash-oo-framework/lib//util/exception.sh
+++(exception.sh:43): command_not_found_handle(): local lineNo=88
+++(exception.sh:44): command_not_found_handle(): local undefinedObject=
+++(exception.sh:45): command_not_found_handle(): local 'type=dummy error'
+++(exception.sh:47): command_not_found_handle(): [[ '' == \(*\) ]]
+++(exception.sh:52): command_not_found_handle(): [[ -z '' ]]
+++(exception.sh:54): command_not_found_handle(): undefinedObject='dummy error'
+++(exception.sh:57): command_not_found_handle(): [[ '' -gt 0 ]]
+++(exception.sh:77): command_not_found_handle(): [[ 1 -ge 25 ]]
+++(exception.sh:83): command_not_found_handle(): exception=('88' 'dummy error' '/home/erwann/github/bash-oo-framework/lib//util/exception.sh')
+++(exception.sh:83): command_not_found_handle(): local -a exception
+++(exception.sh:85): command_not_found_handle(): Exception::FillExceptionWithTraceElements
+++(exception.sh:21): Exception::FillExceptionWithTraceElements(): local 'IFS=
'
++++(exception.sh:22): Exception::FillExceptionWithTraceElements(): Exception::DumpBacktrace 3
++++(exception.sh:241): Exception::DumpBacktrace(): local -i startFrom=3
++++(exception.sh:246): Exception::DumpBacktrace(): local 'IFS=     
'
++++(exception.sh:248): Exception::DumpBacktrace(): local -i i=0
++++(exception.sh:250): Exception::DumpBacktrace(): caller 0
++++(exception.sh:252): Exception::DumpBacktrace(): ((  0 + 1 >= 3  ))
++++(exception.sh:260): Exception::DumpBacktrace(): i+=1
++++(exception.sh:250): Exception::DumpBacktrace(): caller 1
++++(exception.sh:252): Exception::DumpBacktrace(): ((  1 + 1 >= 3  ))
++++(exception.sh:260): Exception::DumpBacktrace(): i+=1
++++(exception.sh:250): Exception::DumpBacktrace(): caller 2
++++(exception.sh:252): Exception::DumpBacktrace(): ((  2 + 1 >= 3  ))
+++++(exception.sh:254): Exception::DumpBacktrace(): caller 2
++++(exception.sh:254): Exception::DumpBacktrace(): trace=('88' 'command_not_found_handle' '/home/erwann/github/bash-oo-framework/lib//util/exception.sh')
++++(exception.sh:254): Exception::DumpBacktrace(): local -a trace
++++(exception.sh:256): Exception::DumpBacktrace(): echo 88
++++(exception.sh:257): Exception::DumpBacktrace(): echo command_not_found_handle
++++(exception.sh:258): Exception::DumpBacktrace(): echo /home/erwann/github/bash-oo-framework/lib//util/exception.sh
++++(exception.sh:260): Exception::DumpBacktrace(): i+=1
++++(exception.sh:250): Exception::DumpBacktrace(): caller 3
++++(exception.sh:252): Exception::DumpBacktrace(): ((  3 + 1 >= 3  ))
+++++(exception.sh:254): Exception::DumpBacktrace(): caller 3
++++(exception.sh:254): Exception::DumpBacktrace(): trace=('16' 'foo' 'tangled.sh')
++++(exception.sh:254): Exception::DumpBacktrace(): local -a trace
++++(exception.sh:256): Exception::DumpBacktrace(): echo 16
++++(exception.sh:257): Exception::DumpBacktrace(): echo foo
++++(exception.sh:258): Exception::DumpBacktrace(): echo tangled.sh
++++(exception.sh:260): Exception::DumpBacktrace(): i+=1
++++(exception.sh:250): Exception::DumpBacktrace(): caller 4
++++(exception.sh:252): Exception::DumpBacktrace(): ((  4 + 1 >= 3  ))
+++++(exception.sh:254): Exception::DumpBacktrace(): caller 4
++++(exception.sh:254): Exception::DumpBacktrace(): trace=('21' 'source' 'tangled.sh')
++++(exception.sh:254): Exception::DumpBacktrace(): local -a trace
++++(exception.sh:256): Exception::DumpBacktrace(): echo 21
++++(exception.sh:257): Exception::DumpBacktrace(): echo source
++++(exception.sh:258): Exception::DumpBacktrace(): echo tangled.sh
++++(exception.sh:260): Exception::DumpBacktrace(): i+=1
++++(exception.sh:250): Exception::DumpBacktrace(): caller 5
+++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
+++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
+++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
+++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
+++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
+++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
+++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
+++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
+++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
+++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
+++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
+++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
+++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
+++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
+++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
+++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
+++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
+++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
+++(exception.sh:87): command_not_found_handle(): Console::WriteStdErr
+++(Console.sh:5): Console::WriteStdErr(): cat

+++(Console.sh:6): Console::WriteStdErr(): return
++++(exception.sh:88): command_not_found_handle(): echo
++++(exception.sh:88): command_not_found_handle(): echo x
++++(exception.sh:88): command_not_found_handle(): echo
++++(exception.sh:88): command_not_found_handle(): echo
++++(exception.sh:88): command_not_found_handle(): echo
++++(exception.sh:88): command_not_found_handle(): UI.Color.Italics
++++(exception.sh:30): command_not_found_handle(): local 'IFS=  
'
++++(exception.sh:33): command_not_found_handle(): [[ UI.Color.Italics = \(\ \s\e\t\ \-*\;\ \t\r\u\e* ]]
++++(exception.sh:38): command_not_found_handle(): Exception::CustomCommandHandler UI.Color.Italics
++++(exception.sh:17): Exception::CustomCommandHandler(): return 1
++++(exception.sh:38): command_not_found_handle(): true
++++(exception.sh:40): command_not_found_handle(): local exit_code=UI.Color.Italics
++++(exception.sh:41): command_not_found_handle(): shift
++++(exception.sh:42): command_not_found_handle(): local script=/home/erwann/github/bash-oo-framework/lib//util/exception.sh
++++(exception.sh:43): command_not_found_handle(): local lineNo=88
++++(exception.sh:44): command_not_found_handle(): local undefinedObject=
++++(exception.sh:45): command_not_found_handle(): local 'type=dummy error'
++++(exception.sh:47): command_not_found_handle(): [[ '' == \(*\) ]]
++++(exception.sh:52): command_not_found_handle(): [[ -z '' ]]
++++(exception.sh:54): command_not_found_handle(): undefinedObject='dummy error'
++++(exception.sh:57): command_not_found_handle(): [[ '' -gt 0 ]]
++++(exception.sh:77): command_not_found_handle(): [[ 2 -ge 25 ]]
++++(exception.sh:83): command_not_found_handle(): exception=('88' 'dummy error' '/home/erwann/github/bash-oo-framework/lib//util/exception.sh')
++++(exception.sh:83): command_not_found_handle(): local -a exception
++++(exception.sh:85): command_not_found_handle(): Exception::FillExceptionWithTraceElements
++++(exception.sh:21): Exception::FillExceptionWithTraceElements(): local 'IFS=
'
+++++(exception.sh:22): Exception::FillExceptionWithTraceElements(): Exception::DumpBacktrace 3
+++++(exception.sh:241): Exception::DumpBacktrace(): local -i startFrom=3
+++++(exception.sh:246): Exception::DumpBacktrace(): local 'IFS=    
'
+++++(exception.sh:248): Exception::DumpBacktrace(): local -i i=0
+++++(exception.sh:250): Exception::DumpBacktrace(): caller 0
+++++(exception.sh:252): Exception::DumpBacktrace(): ((  0 + 1 >= 3  ))
+++++(exception.sh:260): Exception::DumpBacktrace(): i+=1
+++++(exception.sh:250): Exception::DumpBacktrace(): caller 1
+++++(exception.sh:252): Exception::DumpBacktrace(): ((  1 + 1 >= 3  ))
+++++(exception.sh:260): Exception::DumpBacktrace(): i+=1
+++++(exception.sh:250): Exception::DumpBacktrace(): caller 2
+++++(exception.sh:252): Exception::DumpBacktrace(): ((  2 + 1 >= 3  ))
++++++(exception.sh:254): Exception::DumpBacktrace(): caller 2
+++++(exception.sh:254): Exception::DumpBacktrace(): trace=('88' 'command_not_found_handle' '/home/erwann/github/bash-oo-framework/lib//util/exception.sh')
+++++(exception.sh:254): Exception::DumpBacktrace(): local -a trace
+++++(exception.sh:256): Exception::DumpBacktrace(): echo 88
+++++(exception.sh:257): Exception::DumpBacktrace(): echo command_not_found_handle
+++++(exception.sh:258): Exception::DumpBacktrace(): echo /home/erwann/github/bash-oo-framework/lib//util/exception.sh
+++++(exception.sh:260): Exception::DumpBacktrace(): i+=1
+++++(exception.sh:250): Exception::DumpBacktrace(): caller 3
+++++(exception.sh:252): Exception::DumpBacktrace(): ((  3 + 1 >= 3  ))
++++++(exception.sh:254): Exception::DumpBacktrace(): caller 3
+++++(exception.sh:254): Exception::DumpBacktrace(): trace=('88' 'command_not_found_handle' '/home/erwann/github/bash-oo-framework/lib//util/exception.sh')
+++++(exception.sh:254): Exception::DumpBacktrace(): local -a trace
+++++(exception.sh:256): Exception::DumpBacktrace(): echo 88
+++++(exception.sh:257): Exception::DumpBacktrace(): echo command_not_found_handle
+++++(exception.sh:258): Exception::DumpBacktrace(): echo /home/erwann/github/bash-oo-framework/lib//util/exception.sh
+++++(exception.sh:260): Exception::DumpBacktrace(): i+=1
+++++(exception.sh:250): Exception::DumpBacktrace(): caller 4
+++++(exception.sh:252): Exception::DumpBacktrace(): ((  4 + 1 >= 3  ))
++++++(exception.sh:254): Exception::DumpBacktrace(): caller 4
+++++(exception.sh:254): Exception::DumpBacktrace(): trace=('16' 'foo' 'tangled.sh')
+++++(exception.sh:254): Exception::DumpBacktrace(): local -a trace
+++++(exception.sh:256): Exception::DumpBacktrace(): echo 16
+++++(exception.sh:257): Exception::DumpBacktrace(): echo foo
+++++(exception.sh:258): Exception::DumpBacktrace(): echo tangled.sh
+++++(exception.sh:260): Exception::DumpBacktrace(): i+=1
+++++(exception.sh:250): Exception::DumpBacktrace(): caller 5
+++++(exception.sh:252): Exception::DumpBacktrace(): ((  5 + 1 >= 3  ))
++++++(exception.sh:254): Exception::DumpBacktrace(): caller 5
+++++(exception.sh:254): Exception::DumpBacktrace(): trace=('21' 'source' 'tangled.sh')
+++++(exception.sh:254): Exception::DumpBacktrace(): local -a trace
+++++(exception.sh:256): Exception::DumpBacktrace(): echo 21
+++++(exception.sh:257): Exception::DumpBacktrace(): echo source
+++++(exception.sh:258): Exception::DumpBacktrace(): echo tangled.sh
+++++(exception.sh:260): Exception::DumpBacktrace(): i+=1
+++++(exception.sh:250): Exception::DumpBacktrace(): caller 6
++++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++++(exception.sh:22): Exception::FillExceptionWithTraceElements(): for traceElement in $(Exception::DumpBacktrace ${skipBacktraceCount:-3})
++++(exception.sh:24): Exception::FillExceptionWithTraceElements(): exception+=("$traceElement")
++++(exception.sh:87): command_not_found_handle(): Console::WriteStdErr
++++(Console.sh:5): Console::WriteStdErr(): cat

In full: https://pastebin.com/3TpPKGBB https://pastebin.com/cppu98uZ

rogard commented 6 months ago
$ alias throw                                 
alias throw='__EXCEPTION_TYPE__=${e:-Manually invoked} command_not_found_handle'
rogard commented 6 months ago

The export command below is necessary in my setup in order to get the call stack to produces visible output. However, the predicate UI.Color.IsAvailable seems too strong, because the terminal does allow for colorized fonts by default. Further, it's unfortunate that the fallback mechanism outputs blank lines.

Colors.sh

alias UI.Color.IsAvailable='[ $(tput colors 2>/dev/null || echo 0) -ge 16 ] && [ -t 1 ]'
if UI.Color.IsAvailable
then
  alias UI.Color.Default="echo \$'\033[0m'"

# truncated code

else
  alias UI.Color.Default="echo"

# truncated code

fi

Terminal:

$ source tangled.sh
$ alias UI.Color.IsAvailable
alias UI.Color.IsAvailable='[ $(tput colors 2>/dev/null || echo 0) -ge 16 ] && [ -t 1 ]'
$ UI.Color.IsAvailable && echo 'true' || echo 'false' 
false
$ tput colors            
tput: No value for $TERM and no -T specified
$ echo $TERM
dumb
$ export TERM=xterm-256color
$ source tangled.sh

 x UNCAUGHT EXCEPTION: Undefined command (echoo)
   |} * Undefined command [tangled.sh:20]
   |} x echoo [tangled.sh:20]
rogard commented 6 months ago

This solves the problem permanently:

~/.bashrc

TERM=xterm-256color; export TERM # added