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

The redirects section is handled automatically by AOLserver. If the response code matches, and a response hasn't been sent, this page is returned. This page could be a tcl script, adp or whatever. This page also has full access to the errorInfo global, which identifies the error.

I've been playing around with error code lately on AOLserver and it seems that handling or not handling errors can be easily messed up. I suspect that it is done wrong in a lot of places in OpenACS, making it hard to track down either the cause of the error or the code which initially called the code which caused the error (you need both). Also, it can be very tricky to catch and handle errors inside filters. If everything isn't done properly you end up with impossible to find bugs, usually an error about an incorrect return from the filter.

So the first point is that you can use a 500 redirect to return a custom error page in AOLserver. I think this is a new feature, not sure. Second point: try to not use catch except to undo things which absolutely must be undone. For instance, if you open a file, you need to close the file, but then you must propigate the error:

if {[catch {
 set fd [open $file r]
 ...
} err ]} {
    global errorInfo
    set savedInfo $errorInfo
    close $fd
    error $err $savedInfo
}

Third point: error handling could be moved to global/500-error.tcl or whatever.