[Checkins] SVN: zope.exceptions/trunk/ Fallback to traceback.format_tb when the formatter is called recursively.
Brian Sutherland
jinty at web.de
Wed Jul 20 12:51:22 EDT 2011
Log message for revision 122306:
Fallback to traceback.format_tb when the formatter is called recursively.
i.e. Don't let errors in the formatter pass silently.
This patch saves lots of hair pulling with doctest encoding issues under
zope.testrunner.
Changed:
U zope.exceptions/trunk/CHANGES.txt
U zope.exceptions/trunk/src/zope/exceptions/exceptionformatter.py
U zope.exceptions/trunk/src/zope/exceptions/tests/test_exceptionformatter.py
-=-
Modified: zope.exceptions/trunk/CHANGES.txt
===================================================================
--- zope.exceptions/trunk/CHANGES.txt 2011-07-20 16:32:22 UTC (rev 122305)
+++ zope.exceptions/trunk/CHANGES.txt 2011-07-20 16:51:22 UTC (rev 122306)
@@ -5,6 +5,8 @@
3.6.2 (unreleased)
------------------
+- Fallback to traceback.format_tb when the formatter is called recursively.
+ i.e. Don't let errors in the formatter pass silently.
3.6.1 (2010-07-06)
------------------
Modified: zope.exceptions/trunk/src/zope/exceptions/exceptionformatter.py
===================================================================
--- zope.exceptions/trunk/src/zope/exceptions/exceptionformatter.py 2011-07-20 16:32:22 UTC (rev 122305)
+++ zope.exceptions/trunk/src/zope/exceptions/exceptionformatter.py 2011-07-20 16:51:22 UTC (rev 122306)
@@ -171,7 +171,8 @@
while tb is not None and (limit is None or n < limit):
if tb.tb_frame.f_locals.get('__exception_formatter__'):
# Stop recursion.
- result.append('(Recursive formatException() stopped)\n')
+ result.append('(Recursive formatException() stopped, trying traceback.format_tb)\n')
+ result.extend(traceback.format_tb(tb))
break
line = self.formatLine(tb)
result.append(line + '\n')
Modified: zope.exceptions/trunk/src/zope/exceptions/tests/test_exceptionformatter.py
===================================================================
--- zope.exceptions/trunk/src/zope/exceptions/tests/test_exceptionformatter.py 2011-07-20 16:32:22 UTC (rev 122305)
+++ zope.exceptions/trunk/src/zope/exceptions/tests/test_exceptionformatter.py 2011-07-20 16:51:22 UTC (rev 122306)
@@ -152,6 +152,29 @@
' ^',
'SyntaxError: invalid syntax'])
+ def testRecursionFailure(self):
+ from zope.exceptions.exceptionformatter import TextExceptionFormatter
+ class FormatterException(Exception):
+ pass
+
+ class FailingFormatter(TextExceptionFormatter):
+ def formatLine(self, tb):
+ raise FormatterException("Formatter failed")
+
+ fmt = FailingFormatter()
+ try:
+ raise ExceptionForTesting
+ except ExceptionForTesting:
+ try:
+ fmt.formatException(*sys.exc_info())
+ except FormatterException:
+ s = tb()
+ # Recursion was detected
+ self.assertTrue('(Recursive formatException() stopped, trying traceback.format_tb)' in s, s)
+ # and we fellback to the stdlib rather than hid the real error
+ self.assertEquals(s.splitlines()[-2], ' raise FormatterException("Formatter failed")')
+ self.assertTrue('FormatterException: Formatter failed' in s.splitlines()[-1])
+
def test_suite():
return makeSuite(Test)
More information about the checkins
mailing list