GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Issues when showing broken `Exception.__notes__` · Issue #103895 · python/cpython

Issues when showing broken Exception.__notes__ #103895

New issue
Copy link
New issue
Copy link
Closed
Closed
Issues when showing broken Exception.__notes__#103895
Copy link
Assignees
ambv
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@pR0Ps
pR0Ps
opened on Apr 26, 2023
Issue body actions

Bug report

When notes on an exception cannot be shown because the repr and str raise exceptions, a <note str() failed> message is shown instead. In the case where exception.__notes__ is not a sequence and cannot be shown, a <__notes__ repr() failed> is shown. In the second case, the message does not include a trailing newline.

__notes__ is a list containing a broken "note" - output includes a newline:

class A:
    def __repr__(self):
        raise Exception()

e = Exception()
e.__notes__ = [A()]  # !!!
raise e
user@host $ ./repro.py
Traceback (most recent call last):
  File "./repro.py", line 8, in <module>
    raise e
Exception
<note str() failed>
user@host $ 

__notes__ is just a single broken "note" - output does not include a newline:

class A:
    def __repr__(self):
        raise Exception()

e = Exception()
e.__notes__ = A()  # !!!
raise e
user@host $ ./repro.py
Traceback (most recent call last):
  File "./repro.py", line 8, in <module>
    raise e
Exception
<__notes__ repr() failed>user@host $ 

Additionally, when __notes__ is a string/bytes, the contents are expoded over multiple lines because of an isinstance(__notes__, Sequence) check.

String:

e = Exception()
e.__notes__ = "a note"
raise e
user@host $ ./repro.py
Traceback (most recent call last):
  File "./repro.py", line 8, in <module>
    raise e
Exception
a

n
o
t
e
user@host $ 

Bytes:

e = Exception()
e.__notes__ = b"a note"
raise e
user@host $ ./repro.py
Traceback (most recent call last):
  File "./repro.py", line 8, in <module>
    raise e
Exception
97
32
110
111
116
101
user@host $ 

Even though the above are all edge cases, since there are some checks that handle these cases already, it makes sense to handle them more gracefully.

Your environment

  • CPython versions tested on: 3.12.0a7+
  • Operating system and architecture: macOS Mojave (x86)

Linked PRs

  • gh-103895: Improve how invalid Exception.__notes__ are displayed #103897

Activity

  1. pR0Ps
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Apr 26, 2023
  2. pR0Ps
    changed the title [-]No trailing newline when showing broken `Exception .__notes__`[/-] [+]Issues when showing broken `Exception.__notes__`[/+] on Apr 26, 2023
  3. gaogaotiantian commented on Apr 26, 2023

    @gaogaotiantian
    gaogaotiantian
    on Apr 26, 2023
    Member
    More actions

    Is Exception.__notes__ supposed to be directly written? add_note() is definitely the recommended interface to use the feature. The docs mentioned __notes__ as a "list of the notes", and is breaking that a "corner case", or simply the wrong way to use it?

  4. pR0Ps commented on Apr 26, 2023

    @pR0Ps
    pR0Ps
    on Apr 26, 2023
    ContributorAuthor
    More actions

    It is not supposed to be directly written (as far as I can tell), but while I was experimenting with some unrelated exception handling I was digging into this and noticed the inconsistency with the newlines so I figured I'd make a quick patch.

    The only reason I bothered at all is because there's already some amount of handling of invalid notes so it seems it's at least been considered that someone may write Exception.__notes__ directly.

  5. iritkatriel
    added a commit that references this issue on May 1, 2023

    gh-103895: Improve how invalid `Exception.__notes__` are displayed (#…

    487f55d
  6. iritkatriel commented on May 1, 2023

    @iritkatriel
    iritkatriel
    on May 1, 2023
    Member
    More actions

    Merged into 3.12. Leaving open pending decision about backporting to 3.11.

    Reacted by Carey Metcalfe
  7. carljm
    added 2 commits that reference this issue on May 1, 2023

    Merge branch 'main' into supermon

    159b2aa

    Merge branch 'main' into inlinecomp2

    1274e2b
  8. iritkatriel
    assigned
    ambv
    on Jun 27, 2023
  9. iritkatriel commented on Jun 27, 2023

    @iritkatriel
    iritkatriel
    on Jun 27, 2023
    Member
    More actions

    Assigned to @ambv for a backport decision.

  10. hugovk commented on Nov 10, 2023

    @hugovk
    hugovk
    on Nov 10, 2023
    Member
    More actions

    @ambv Shall we backport or close this issue?

  11. iritkatriel
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Nov 26, 2023
  12. iritkatriel
    closed this as completedon May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @ambv
    ambv

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.