Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow exception handlers to accept BaseExceptions #3011

Open
1 task done
nicholas-watson-hx opened this issue Nov 26, 2024 · 1 comment
Open
1 task done

Allow exception handlers to accept BaseExceptions #3011

nicholas-watson-hx opened this issue Nov 26, 2024 · 1 comment

Comments

@nicholas-watson-hx
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe.

I've recently upgraded from Sanic 21.12.0 -> 23.12.0 and over this version boundary the behaviour of the exception Handler has changed (commit d255d1a, file sanic/mixins/exceptions.py) to accept Union[Exception, List[Exception]].

We're using the exception handler to catch asyncio's CancelledError which inherits from BaseException (see https://github.com/python/cpython/blob/3.9/Lib/asyncio/exceptions.py#L9). However with the Sanic upgrade Mypy is raising errors that we cannot use the exception handler to handle CancelledError, I've done some further investigation in ways of fixing this but they all seem to be limited by the argument types of fn exception in sanic/mixins/exceptions.py

Describe the solution you'd like

Allow the exception handler to handle BaseExceptions.

Additional context

No response

@ahopkins
Copy link
Member

Hmm... will have to think about this and investigate it. I do remember this being a very intentional decision, and that it was a bit of an anti-pattern that we allowed it at the time. It especially was a conflict when we overhauled the streaming pattern as it exposed some problems relating to catching timeouts (which are CancelledError), etc.

What's the use case, and how are you relying upon CancelledError?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants