Skip to content

HTTPException should retain cause information #3096

Closed
@jcjf

Description

Long story short

I would like to use a pattern like:

try:
    do_something()
except SomeException as e:
    raise HTTPInternalServerError(reason='My message') from e

with cause information retained. Does it make sense to implement HTTPException.__bool__() to always True?

Expected behaviour

Two tracebacks separated by The above exception was the direct cause of the following exception:

Actual behaviour

The cause information is lost, because traceback.TracebackException evaluates the truthiness of the exception value to determine whether cause lines are produced. For HTTPException, truthiness is resolved via StreamResponse.__len__() which returns 0.

Steps to reproduce

Your environment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions