Created by ZopeOrgSite . Last modified 2003-08-26 10:36:54.
For page templates one has a detailed error mechanism
via the tal:on-error
tag. Usually this calles a python script
to do the error handling.
Unfortunately simply printing a stack trace seems to quite complicated (compared to the tip for DTML ).
I use an external method for this, as it seems one has to surround the security limitiations of Zope scripts; thus I put the following code snippet in the "Extensions" directory:
import traceback import StringIO def print_traceback(trace): fp = StringIO.StringIO() traceback.print_exc(file=fp) return fp.getvalue()
(the external method object is stored in /scripts/traceback
)
and call this in my error handling script:
error = _['error'] print "<!-- Error %s!, error value is: %s -->" % (error.type, error.value) print "<!-- Traceback follows : %s -->" % context.scripts.traceback(error.traceback) return printed
Note that the error handling script should have the Namespace
assigned to _
(via the bindings
tab), and that
the error handling attribute should be written like
tal:on-error="structure here/scripts/errorHandler"
to avoid HTML-encoding the HTML-comments and exposing the stack trace
in the rendered HTML.
(maybe there is a simpler solution, but I have found none.)