Skip to content

exceptions raised before calling task_status.started loses cause & context #3261

@jakkdl

Description

@jakkdl

This snippet eats cause&context

trio/src/trio/_core/_run.py

Lines 1387 to 1389 in 9c909fa

except BaseExceptionGroup as exc:
if len(exc.exceptions) == 1:
raise exc.exceptions[0] from None

a la https://flake8-async.readthedocs.io/en/latest/rules.html#async123

we currently only run the ruff reimplementation of flake8-async, which hasn't added that rule. So we should maybe consider running flake8-async as well, disabling any rules that ruff handles [better], or are noisy.

It should make use of trio._util.raise_saving_context.

repro:

import trio


async def task(task_status: trio.TaskStatus) -> None:
    e = ValueError("foo")
    e.__cause__ = SyntaxError("bar")
    e.__context__ = TypeError("baz")
    raise e

async def main() -> None:
    async with trio.open_nursery() as nursery:
        await nursery.start(task)

try:
    trio.run(main)
except ExceptionGroup as excgroup:
    # should be SyntaxError, is None
    print(excgroup.exceptions[0].__cause__)
    # should be TypeError, is the exceptiongroup
    print(repr(excgroup.exceptions[0].__context__))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions