PythiloLesson 9 of 12 · progress kept in this browser

Separate failures without flattening away structure

Concurrent operations can fail independently. ExceptionGroup preserves that structure instead of losing all but the first failure. Catching the group as one generic error prevents a caller from distinguishing retryable failures from programming bugs.

A split operation can select one exception type while retaining nested groups and the original leaves. This exercise returns leaf messages for reporting only; it does not pretend that flattening is sufficient for recovery. A recovery policy should continue using subgroup structure and avoid retrying work whose side effects may already have committed.

group=ExceptionGroup("batch",[
    ValueError("bad input"),
    OSError("offline")])
selected,rest=group.split(OSError)
print(type(selected.exceptions[0]).__name__)
print(type(rest.exceptions[0]).__name__)
Your task

Implement error_leaves(error) returning leaf exception class names in depth-first order. Handle nested BaseExceptionGroup and ordinary exceptions without including group names.