aboutsummaryrefslogtreecommitdiff
path: root/tests/error.test
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2023-05-18 15:34:26 +1000
committerSteve Bennett <steveb@workware.net.au>2023-06-21 09:17:47 +1000
commit0b08e74e656c6bfb65c6f38657be05bb463f54e6 (patch)
treefaa80db8a2cd6f24cf890ad6730c00f4d7dd2738 /tests/error.test
parentf07c53e38d55f0c7c648b7818798138d91053527 (diff)
downloadjimtcl-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/error.test')
-rw-r--r--tests/error.test12
1 files changed, 6 insertions, 6 deletions
diff --git a/tests/error.test b/tests/error.test
index d226900..5669b7b 100644
--- a/tests/error.test
+++ b/tests/error.test
@@ -11,12 +11,12 @@ proc b {} {
}
}
-test error-1.1 "Rethrow caught error" {
+test error-1.1 {Rethrow caught error} -body {
set rc [catch {b} msg]
#puts stderr "error-1.1\n[errorInfo $msg]\n"
list $rc $msg [basename-stacktrace [info stacktrace]]
-} {1 {error thrown from a} {{} error.test 4 a error.test 8 b error.test 15}}
+} -result {1 {error thrown from a} {a error.test 4 error\ \{error\ thrown\ f... b error.test 8 a test error.test 15 b {} error.test 14 test\ error-1.1\ \{Rethr...}}
proc c {} {
a
@@ -30,22 +30,22 @@ proc e {} {
d
}
-test error-1.2 "Modify stacktrace" {
+test error-1.2 {Modify stacktrace} -body {
set rc [catch {e} msg]
set st [info stacktrace]
# Now elide one entry from the stacktrace
#puts [errorInfo $msg]
set newst {}
- foreach {p f l} $st {
+ foreach {p f l cmd} $st {
if {$p ne "d"} {
- lappend newst $p $f $l
+ lappend newst $p $f $l $cmd
}
}
# Now rethrow with the new stack
set rc [catch {error $msg $newst} msg]
#puts [errorInfo $msg]
basename-stacktrace [info stacktrace]
-} {{} error.test 4 a error.test 22 c error.test 26 e error.test 34}
+} -result {a error.test 4 error\ \{error\ thrown\ f... c error.test 22 a e error.test 30 d test error.test 34 e {} error.test 33 test\ error-1.2\ \{Modif...}
# Package should be able to invoke exit, which should exit if not caught
test error-2.1 "Exit from package" {