Skip to content

Exceptions notes (PEP 678 since Python 3.11) are not properly formatted #980

@Delgan

Description

@Delgan

The following code:

import sys
from loguru import logger


@logger.catch
def main():
    try:
        raise ValueError("Error")
    except Exception as e:
        e.add_note("Note 1")
        e.add_note("Note 2")
        raise


logger.remove()
logger.add(sys.stderr, diagnose=True, backtrace=False, colorize=True)

main()

Causes the ValueError to be formatted as follows:

Traceback (most recent call last):

  File "/home/delgan/test.py", line 18, in <module>
    main()
    └ <function main at 0x7f77a3142020>

  File "/home/delgan/test.py", line 8, in main
    raise ValueError("Error")
ValueError: Error
Note 1

Note 2

Expected output is more like this:

Traceback (most recent call last):

  File "/home/delgan/test.py", line 18, in <module>
    main()
    └ <function main at 0x7f77a3142020>

  File "/home/delgan/test.py", line 8, in main
    raise ValueError("Error")

ValueError: Error
Note 1
Note 2

Also the ansi colors are wrong, as currently "Note 2" is highlighted instead of "ValueError: Error".

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovement to an already existing feature

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions