#3232·trio

Add exception message for easier debugging with `Cancelled`

Author: Zac-HDCreated Mar 27, 2025Updated Aug 4, 2026
Labelsdesign discussiondebugging

Occasionally we end up digging through logs trying to work out why something was cancelled, and eventually it occurred to me that Trio could help with this. I don't have a complete design proposal, but it would be great to handle each of three cases:

  • a deadline was reached.
  • a sibling task in the Nursery raised an exception, including the name of the erroring task
  • someone called CancelScope.cancel(), including the name of the task in which this was called
    • add a new reason: str | None = None param, so that users can explicitly annotate why they cancelled something

I think we could represent this as a string argument to Cancelled like any other exception message; the only tricky part will be threading it through all the cancellation-delivery machinery

Comments and design input most welcome, of course!