Added keyword argument to recoverableException to determine the type of exception logged.

This commit is contained in:
Jeremy Fincher 2003-04-14 07:18:42 +00:00
parent f5cf223ea6
commit 49b8982b3a

View File

@ -130,7 +130,13 @@ def unrecoverableError(msg):
recoverableError(msg) recoverableError(msg)
exit(-1) exit(-1)
def recoverableException(): def recoverableException(type='detailed'):
"""Logs an exception that's recoverable.
The 'type' argument can be either 'detailed' (for a nice cgitb traceback),
'normal' (for a normal traceback), or 'terse' (for a short line stating
the exception raised).
"""
if world.testing: if world.testing:
return return
(E, e, tb) = sys.exc_info() (E, e, tb) = sys.exc_info()
@ -144,9 +150,12 @@ def recoverableException():
else: else:
del lastTimes[0] del lastTimes[0]
try: try:
if not conf.detailedTracebacks: if type == 'detailed' and conf.detailedTracebacks:
1/0 text = cgitb.text((E, e, tb))
text = cgitb.text((E, e, tb)) elif type == 'normal':
text = ''.join(traceback.format_exception(E, e, tb))
elif type == 'terse':
text = exnToString(e)
except: except:
text = ''.join(traceback.format_exception(E, e, tb)) text = ''.join(traceback.format_exception(E, e, tb))
del tb # just to be safe. del tb # just to be safe.
@ -171,6 +180,7 @@ def msg(s, priority='low'):
_writeNewline(sys.stderr, s) _writeNewline(sys.stderr, s)
if colorterm: if colorterm:
sys.stderr.write(ansi.RESET) sys.stderr.write(ansi.RESET)
s = '%s: %s' % (priority.upper(), s)
_writeNewline(_debugfd, s) _writeNewline(_debugfd, s)
_debugfd.flush() _debugfd.flush()
@ -189,4 +199,5 @@ def tracer(frame, event, _):
s = '%s: %s\n' % (frame.f_code.co_filename, frame.f_code.co_name) s = '%s: %s\n' % (frame.f_code.co_filename, frame.f_code.co_name)
_tracefd.write(s) _tracefd.write(s)
_tracefd.flush() _tracefd.flush()
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: