Forum OpenACS Q&A: Re: RFC: How to improve error handling and messages for users

For instance, I have some test procs and a registered filter:

proc ::mytime { time } {

    return [ns_buildsqltime $time]
}

proc ::filter-error { why } {
     source [ns_info pageroot]/err.cmp
     mytime 10:00:00
     return filter_ok

}

ns_register_filter preauth GET /filter-error.tcl filter-error

My error page contains:

global errorInfo

ns_return 500 text/plain "Oops screwed up: $errorInfo"

My err.cmp page contains:

set abcd efgh
set $abcd

When I access /filter-error.tcl, I get the following returned:

Oops screwed up: can't read "efgh": no such variable
    while executing
"set $abcd"
    (file "/usr/local/aolserver/servers/test/pages/err.cmp" line 2)
    invoked from within
"source [ns_info pageroot]/err.cmp"
    (procedure "filter-error" line 2)
    invoked from within
"filter-error preauth"

So the problem was caused by the fact that the efgh var didn't exist. The error was on page err.cmp, which was sourced by the proc filter-error on line two of that proc, which was called as a preauth filter. If I were to fix this error in some way, I would discover that the next line of my filter proc calls another proc which has an error:

Oops screwed up: wrong # args: should be "ns_buildsqltime time ampm"
    while executing
"ns_buildsqltime $time"
    (procedure "mytime" line 3)
    invoked from within
"mytime 10:00:00"
    (procedure "filter-error" line 3)
    invoked from within
"filter-error preauth"

In both cases, the full stack trace helps you easily find and fix the problem.