Skip to content
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

traceback (and threading) drops exception message #71535

Closed
vadmium opened this issue Jun 18, 2016 · 11 comments
Closed

traceback (and threading) drops exception message #71535

vadmium opened this issue Jun 18, 2016 · 11 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@vadmium
Copy link
Member

vadmium commented Jun 18, 2016

BPO 27348
Nosy @vstinner, @rbtcollins, @vadmium
PRs
  • [Do Not Merge] Convert Misc/NEWS so that it is managed by towncrier #552
  • Files
  • none-message.patch
  • Note: 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:

    assignee = None
    closed_at = <Date 2016-09-22.13:13:08.679>
    created_at = <Date 2016-06-18.14:57:36.562>
    labels = ['3.7', 'type-bug', 'library']
    title = 'traceback (and threading) drops exception message'
    updated_at = <Date 2017-03-31.16:36:33.428>
    user = 'https://github.com/vadmium'

    bugs.python.org fields:

    activity = <Date 2017-03-31.16:36:33.428>
    actor = 'dstufft'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-09-22.13:13:08.679>
    closer = 'martin.panter'
    components = ['Library (Lib)']
    creation = <Date 2016-06-18.14:57:36.562>
    creator = 'martin.panter'
    dependencies = []
    files = ['43577']
    hgrepos = []
    issue_num = 27348
    keywords = ['patch', '3.5regression']
    message_count = 11.0
    messages = ['268814', '269465', '269469', '269471', '269472', '269473', '272494', '276664', '276679', '276683', '277216']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'rbcollins', 'python-dev', 'martin.panter']
    pr_nums = ['552']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue27348'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @vadmium
    Copy link
    Member Author

    vadmium commented Jun 18, 2016

    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

    @vadmium
    Copy link
    Member Author

    vadmium commented Jun 29, 2016

    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 value == 'None' or value is None or not valuestr:

    @vadmium vadmium added the stdlib Python modules in the Lib dir label Jun 29, 2016
    @vadmium vadmium changed the title Non-main thread exception handler drops exception message traceback (and threading) drops exception message Jun 29, 2016
    @vadmium vadmium added the type-bug An unexpected behavior, bug, or error label Jun 29, 2016
    @vadmium
    Copy link
    Member Author

    vadmium commented Jun 29, 2016

    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.

    @rbtcollins
    Copy link
    Member

    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.

    @vstinner
    Copy link
    Member

    I agree that ignoring the exception message if str(exc) == 'None' is wrong.

    @vadmium
    Copy link
    Member Author

    vadmium commented Jun 29, 2016

    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.

    @vadmium
    Copy link
    Member Author

    vadmium commented Aug 12, 2016

    Have you had any luck reviewing this Robert?

    @vadmium
    Copy link
    Member Author

    vadmium commented Sep 16, 2016

    I plan to commit this soon, in time for the next release.

    @vadmium vadmium added the 3.7 (EOL) end of life label Sep 16, 2016
    @vstinner
    Copy link
    Member

    "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.

    @vadmium
    Copy link
    Member Author

    vadmium commented Sep 16, 2016

    Yes, a bug fix for 3.5+.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 22, 2016

    New changeset 5859a9e8b214 by Martin Panter in branch '3.5':
    Issue bpo-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 bpo-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 bpo-27348: Merge exception formatting fix from 3.6
    https://hg.python.org/cpython/rev/4261ae29d3e2

    @vadmium vadmium closed this as completed Sep 22, 2016
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants