-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
traceback (and threading) drops exception message #71535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If the exception argument is None or repr(None), it is omitted from the report when a thread raises an unhandled exception: >>> def raise_exception(e):
... raise e
...
>>> t = Thread(target=raise_exception, args=(Exception(None),)); t.start(); t.join()
Exception in thread Thread-1:
Traceback (most recent call last):
File "/home/proj/python/cpython/Lib/threading.py", line 916, in _bootstrap_inner
self.run()
File "/home/proj/python/cpython/Lib/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "<stdin>", line 2, in raise_exception
Exception
>>> t = Thread(target=raise_exception, args=(Exception("None"),)); t.start(); t.join()
Exception in thread Thread-2:
Traceback (most recent call last):
File "/home/proj/python/cpython/Lib/threading.py", line 916, in _bootstrap_inner
self.run()
File "/home/proj/python/cpython/Lib/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "<stdin>", line 2, in raise_exception
Exception Compare the result with other exception messages, the normal sys.excepthook() report, and Python 2: >>> t = Thread(target=raise_exception, args=(Exception("NONE"),)); t.start(); t.join()
Exception in thread Thread-3:
Traceback (most recent call last):
File "/home/proj/python/cpython/Lib/threading.py", line 916, in _bootstrap_inner
self.run()
File "/home/proj/python/cpython/Lib/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "<stdin>", line 2, in raise_exception
Exception: NONE
>>> raise Exception(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Exception: None |
I traced this back to revision 73afda5a4e4c (bpo-17911), which includes this change to traceback._format_final_exc_line(): -if value is None or not valuestr: |
If I remove the value == 'None' check, there are two failures in the test suite:
def test_without_exception(self):
err = traceback.format_exception_only(None, None)
self.assertEqual(err, ['None\n']) It was apparently added so that print_exc() would output “None” when called with no exception set. This is the case for Python 2. However in the Python 3 versions I have tried, print_exc() either raises AttributeError or prints “NoneType”. In any case, the test does not seem to be testing anything valid according to the documentation, so I propose to remove it. |
hmm, can you give me a change to page this in? I'm pretty sure I saw breakage in external libraries prompting me to add the test and fix. I'd rather not recause that. |
I agree that ignoring the exception message if str(exc) == 'None' is wrong. |
Yeah sure I can give you a chance to consider this (I assume you meant “chance” :). But neither of the tests I mentioned were added by you as far as I know. Maybe you are thinking of some other test. |
Have you had any luck reviewing this Robert? |
I plan to commit this soon, in time for the next release. |
"Issue bpo-27348: In the traceback module, restore the formatting of exception messages like "Exception: None". This fixes a regression introduced in 3.5a2." Humn, if it is described as a regression, it means that it's a bug no? You plan to push the change into Python 3.5, 3.6 and 3.7, right? none-message.patch: LGTM. |
Yes, a bug fix for 3.5+. |
New changeset 5859a9e8b214 by Martin Panter in branch '3.5': New changeset d1455d14accd by Martin Panter in branch '3.6': New changeset 4261ae29d3e2 by Martin Panter in branch 'default': |
Misc/NEWS
so that it is managed by towncrier #552Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: