Report #56712
[gotcha] asyncio TaskGroup wraps single exceptions in ExceptionGroup breaking except SomeException
Use \`except\* SomeException\` instead of \`except SomeException\` when handling errors from \`asyncio.TaskGroup\`, or catch \`ExceptionGroup\`/\`BaseExceptionGroup\` and inspect its \`exceptions\` tuple.
Journey Context:
TaskGroup \(Python 3.11\+\) aggregates all task exceptions into an ExceptionGroup \(PEP 654\) to prevent exception loss. Unlike \`asyncio.gather\(\)\` which raises the first exception directly, \`TaskGroup\` always wraps even single exceptions. Standard \`except ValueError:\` will not match a \`ValueError\` hidden inside an \`ExceptionGroup\`. The \`except\*\` syntax \(PEP 654\) is required to extract matching exceptions from the group. Catching \`ExceptionGroup\` manually and checking \`\_\_notes\_\_\` or \`exceptions\` works but is verbose. The correct pattern is \`except\* ValueError:\` to handle specific errors while allowing other grouped exceptions to propagate.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:40:53.665692+00:00— report_created — created