diff options
author | Steve Bennett <steveb@workware.net.au> | 2023-05-18 15:34:26 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2023-06-21 09:17:47 +1000 |
commit | 0b08e74e656c6bfb65c6f38657be05bb463f54e6 (patch) | |
tree | faa80db8a2cd6f24cf890ad6730c00f4d7dd2738 /tests/misc.test | |
parent | f07c53e38d55f0c7c648b7818798138d91053527 (diff) | |
download | jimtcl-0b08e74e656c6bfb65c6f38657be05bb463f54e6.zip jimtcl-0b08e74e656c6bfb65c6f38657be05bb463f54e6.tar.gz jimtcl-0b08e74e656c6bfb65c6f38657be05bb463f54e6.tar.bz2 |
core: Display errors in a more "pythonesque" way
A typical error message now looks like this:
t4.tcl:2: Error: syntax error in expression: "blah"
Traceback (most recent call last):
File "t4.tcl", line 14
c 1 2 3
File "t4.tcl", line 10, in c
b a c
File "t4.tcl", line 6, in b
a A14
File "t4.tcl", line 2, in a
expr blah
This is produced by stackdump (that can be replaced), called by errorInfo.
Note that now stacktraces (stacktrace, info stacktrace, $opts(-errorinfo)) include
the running command at each level in addition to proc, file, line. In order for
scripts to detect this new format, a new entry tcl_platform entry has been added:
tcl_platform(stackFormat) = 4 (to signify 4 elements per frame)
In addition, instead of building the error stack frame as the stack
is unwound in response to an error, instead the entire current stack trace
is captured by stacktrace. This means that the trace extends beyond the try/catch
right back to the initial interpreter command.
The 'stacktrace' command is now implemented in C based on the same
code that generates the error stacktrace.
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests/misc.test')
-rw-r--r-- | tests/misc.test | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/tests/misc.test b/tests/misc.test index a997057..cffb0a6 100644 --- a/tests/misc.test +++ b/tests/misc.test @@ -301,25 +301,24 @@ test catch-1.9 "catch no error has no -errorinfo" { list $rc [info exists opts(-errorinfo)] } {0 0} -test return-1.1 "return can rethrow an error" { +test return-1.1 {return can rethrow an error} -body { proc a {} { error "from a" } proc b {} { catch {a} msg opts; return {*}$opts $msg } set rc [catch {b} msg opts] - list $rc $msg [llength $opts(-errorinfo)] -} {1 {from a} 9} + list $rc $msg [basename-stacktrace $opts(-errorinfo)] +} -result {1 {from a} {a misc.test 305 {error {from a}} b misc.test 306 a test misc.test 307 b {} misc.test 304 test\ return-1.1\ \{retu...}} -test return-1.2 "error can rethrow an error" { +test return-1.2 {error can rethrow an error} -body { proc a {} { error "from a" } proc b {} { catch {a} msg; error $msg [info stacktrace] } set rc [catch {b} msg opts] - list $rc $msg [llength $opts(-errorinfo)] -} {1 {from a} 9} + list $rc $msg [basename-stacktrace $opts(-errorinfo)] +} -result {1 {from a} {a misc.test 312 {error {from a}} b misc.test 313 a test misc.test 314 b {} misc.test 311 test\ return-1.2\ \{erro...}} test return-1.3 "return can rethrow no error" { proc a {} { return "from a" } proc b {} { catch {a} msg opts; return {*}$opts $msg } set rc [catch {b} msg opts] - #list $rc $msg [llength $opts(-errorinfo)] list $rc $msg [info exists opts(-errorinfo)] } {0 {from a} 0} |