Multiple Errors

Hi everyone,

I got annoyed by the one ::errorInfo. At my work there are places where you want to see a few errors back. I wrote a script that tracks the errors and stores them, so it is possible to view past errorInfos. It is quite handy from time to time.

I looked for something like this and did not find anything. Hope this helps someone.

Multiple Tcl Errors

Any feedback/issues can be reported to the repository or through here.

A sort of quick-and-dirty variant on this:

proc logErrors {varName args} {
    upvar 0 $varName var
    if {![info exists var] || [string length $::errorInfo] < [string length [lindex $var end]]} {
        lappend var $::errorCode $::errorInfo
    } else {
        lset var end $::errorInfo

Set a trace with a fully-qualified variable name as argument:

trace add variable ::errorInfo write {logErrors ::foo::errorLog}

This variable will collect an even-sized list of error codes and stack traces. This list can be pretty-printed e.g. like this:

foreach {code info} $::foo::errorLog {
    puts "Code: $code\nInfo: $info\n"