Skip to content

strict_exception_groups=True "leaks" the implementation-detail nursery in nursery.start(fn) #2611

Closed
@Zac-HD

Description

@Zac-HD

Currently, exceptions raised from a nursery.start()'ed function will be wrapped in extra ExceptionGroup (aka MultiError), iff it's raised before task_status.started() is called.

I think that for consistency, we should pull such exceptions (which might themselves be ExceptionGroups) out of the group added by the starter-nursery.

import trio

async def startable_fn_which_doesnt_contain_a_nursery(task_status):
    if ...:
        print("Something went wrong")
        raise RuntimeError  # this might be wrapped in an ExceptionGroup
    task_status.started()
    raise ValueError  # ...but this will never be wrapped!

async def main():
    async with trio.open_nursery() as nursery:
        try:
            # Uh-oh!  With strict_exception_groups=True, the hidden inner nursery
            # in `nursery.start` wraps our RuntimeError in an ExceptionGroup :-/
            await nursery.start(startable_fn_which_doesnt_contain_a_nursery)
        except RuntimeError:
            print("No worries, we'll try something else.")

if __name__ == "__main__":
    trio.run(main, strict_exception_groups=False)  # passes
    print("\n==============================================================\n")
    trio.run(main, strict_exception_groups=True)  # fails!

Related to #2544 and possibly #1457.

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