classification
Title: traceback (and threading) drops exception message
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: martin.panter, python-dev, rbcollins, vstinner
Priority: normal Keywords: 3.5regression, patch

Created on 2016-06-18 14:57 by martin.panter, last changed 2017-03-31 16:36 by dstufft. This issue is now closed.

Files
File name Uploaded Description Edit
none-message.patch martin.panter, 2016-06-29 09:56 review
Pull Requests
URL Status Linked Edit
PR 552 closed dstufft, 2017-03-31 16:36
Messages (11)
msg268814 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-06-18 14:57
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
msg269465 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-06-29 05:00
I traced this back to revision 73afda5a4e4c (Issue 17911), which includes this change to traceback._format_final_exc_line():

-if value is None or not valuestr:
+if value == 'None' or value is None or not valuestr:
msg269469 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-06-29 09:56
If I remove the value == 'None' check, there are two failures in the test suite:

1. test_decimal fails, but only because the test was changed in revision 5f3dd0a2b1ab to accommodate the very bug I am complaining about. IMO this was a case of “fixing” the test instead of fixing the bug, so it is okay to restore the test.

2. The following test, added in revision ecaafc32c500:

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.
msg269471 - (view) Author: Robert Collins (rbcollins) * (Python committer) Date: 2016-06-29 10:08
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.
msg269472 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-06-29 10:09
I agree that ignoring the exception message if str(exc) == 'None' is wrong.
msg269473 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-06-29 10:18
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.
msg272494 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-08-12 04:05
Have you had any luck reviewing this Robert?
msg276664 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-09-16 02:09
I plan to commit this soon, in time for the next release.
msg276679 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-09-16 07:14
"Issue #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.
msg276683 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-09-16 08:28
Yes, a bug fix for 3.5+.
msg277216 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-22 10:56
New changeset 5859a9e8b214 by Martin Panter in branch '3.5':
Issue #27348: Restore “Exception: None” formatting in traceback module
https://hg.python.org/cpython/rev/5859a9e8b214

New changeset d1455d14accd by Martin Panter in branch '3.6':
Issue #27348: Merge exception formatting fix from 3.5 into 3.6
https://hg.python.org/cpython/rev/d1455d14accd

New changeset 4261ae29d3e2 by Martin Panter in branch 'default':
Issue #27348: Merge exception formatting fix from 3.6
https://hg.python.org/cpython/rev/4261ae29d3e2
History
Date User Action Args
2017-03-31 16:36:33dstufftsetpull_requests: + pull_request1064
2016-09-22 13:13:08martin.pantersetstatus: open -> closed
resolution: fixed
stage: commit review -> resolved
2016-09-22 10:56:39python-devsetnosy: + python-dev
messages: + msg277216
2016-09-16 08:28:17martin.pantersetmessages: + msg276683
2016-09-16 07:14:13vstinnersetmessages: + msg276679
2016-09-16 02:09:11martin.pantersetstage: patch review -> commit review
messages: + msg276664
versions: + Python 3.7
2016-08-12 04:05:07martin.pantersetmessages: + msg272494
2016-06-29 10:18:51martin.pantersetmessages: + msg269473
2016-06-29 10:09:09vstinnersetnosy: + vstinner
messages: + msg269472
2016-06-29 10:08:58rbcollinssetmessages: + msg269471
2016-06-29 09:56:27martin.pantersetfiles: + none-message.patch

nosy: + rbcollins
messages: + msg269469

keywords: + patch
stage: patch review
2016-06-29 05:00:41martin.pantersettitle: Non-main thread exception handler drops exception message -> traceback (and threading) drops exception message
messages: + msg269465

components: + Library (Lib)
keywords: + 3.5regression
type: behavior
2016-06-18 14:57:36martin.pantercreate