|
Pythomnic » Documentation » Error handling (reporting)
The question of how to actually report and/or record en error is also
important. The usual approach with dumping a stack trace spanning
multiple lines does not play well neither with log files nor with the
client's protocols.
The following reasons make it preferable to include the entire error
text into a single line of text:
1. Cages keep their logs in line-structured files, dumping a multi-line
stack trace would affect the readability of the log, even more so if there
are multiple threads writing to the log simultaneously.
2. The (synchronous) protocols which Pythomnic interfaces support do contain a place where to put the error text on return, but assert no semantics on the contents or the way it will be displayed. 3. It is not known beforehand in which way the client will be reporting the error itself, either to the user directly (in a message box perhaps) or to a log file of its own.
For reporting errors, Pythomnic therefore uses the exc_string function
from exc_string import *
try:
foo()
except:
pmnc_log("failed: %s" % exc_string(), priority = 1)
which returns a single long string containing a readable error text
along with the unfolded stack trace, for example:
SMTPRecipientsRefused("{'-': (550, '<->: User unknown in local recipient table')}") ...
... in sendmail() (smtplib.py:695) <- execute() (smtp_connection.py:187) <- ...
... takes_invocation_proxy() (typecheck.py:365) <- dbc_wrapper() (ipdbc.py:283) ...
... <- execute() (connection_pool.py:566) <- dbc_wrapper() (ipdbc.py:283) <- ...
... execute() (threaded_connection_pool.py:187) <- interlock_shared_invocation_proxy() ...
... (interlockable.py:117) <- __call__() (thread_pool.py:94)
The synchronous Pythomnic interfaces - SOAP, XML-RPC and HTTP all use exc_string to
compose and report the uncaught exception to the client.
|
Features Download Documentation Tutorial |