This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: format_exception raises if str(exception) raises
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: nnorwitz Nosy List: exarkun, georg.brandl, jimjjewett, nnorwitz
Priority: critical Keywords:

Created on 2006-07-30 21:06 by exarkun, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg29383 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2006-07-30 21:06
Previously format_exception_only used _some_str() to
find the string representation of an exception.  In
current trunk@HEAD that code has been factored into
_format_final_exc_line and changed in two ways: it now
calls str(exception) twice instead of once and in one
of those cases, it calls str() directly rather than
through _some_str, which does exception handling.

The end result of this is that application-level code
which uses the traceback module to format exceptions
which previously could not raise exceptions now can
raise exceptions.
msg29384 - (view) Author: Jim Jewett (jimjjewett) Date: 2006-08-02 22:13
Logged In: YES 
user_id=764593

Jp -- is this the same issue as 1515163 (patch 1515343)?  
If so, it should be cleared up in the traceback.py from 
head.  Could you doublecheck?

msg29385 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2006-08-02 22:55
Logged In: YES 
user_id=366566

I don't think those are related.  To clarify, this is the
case I am talking about:

Python 2.5b2 (trunk:50989, Jul 30 2006, 15:42:25) 
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> class X:
...     def __str__(self): 1/0
... 
>>> import traceback
>>> traceback.format_exception_only(X, X())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File
"/home/exarkun/Projects/python/trunk/Lib/traceback.py", line
179, in format_exception_only
    return [_format_final_exc_line(stype, value)]
  File
"/home/exarkun/Projects/python/trunk/Lib/traceback.py", line
205, in _format_final_exc_line
    if value is None or not str(value):
  File "<stdin>", line 2, in __str__
ZeroDivisionError: integer division or modulo by zero
>>> 

Compare this to the Python 2.4 output:

Python 2.4.3 (#2, Apr 27 2006, 14:43:58) 
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> class X:
...      def __str__(self): 1/0
... 
>>> import traceback
>>> traceback.format_exception_only(X, X())
['X: <unprintable instance object>\n']
>>> 
msg29386 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-08-03 06:13
Logged In: YES 
user_id=849994

I have a fix and will apply as soon as trunk is unfrozen.
msg29387 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-08-04 04:50
Logged In: YES 
user_id=33168

Committed revision 51079.
History
Date User Action Args
2022-04-11 14:56:19adminsetgithub: 43748
2006-07-30 21:06:09exarkuncreate