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

Always call custom error handler. #1803

Conversation

alex-oleshkevich
Copy link
Member

@alex-oleshkevich alex-oleshkevich commented Aug 10, 2022

Fixes #1802

Copy link
Member

@euri10 euri10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the logic is good here, we definitely want the custom handler to be processed first or there's no point having one,
I'll let soneone else approve it since I know Starlette a little but less but as far as I know there's no issue changing the logic here,
any thoughts @adriangb or @Kludex ?

@Kludex
Copy link
Member

Kludex commented Aug 11, 2022

This behavior is explicitly mentioned on the documentation:

If `debug` is enabled and an error occurs, then instead of using the installed
500 handler, Starlette will respond with a traceback response.

@alex-oleshkevich
Copy link
Member Author

Well, this is counter-intuitive. Any option to reconsider it?

@Kludex
Copy link
Member

Kludex commented Aug 12, 2022

I don't really see how it's counter-intuitive, because on a normal flow you usually have the handlers, and then you set the debug parameter. Losing priority would make people set the flag, and also comment the handlers.

As a note, in the whole code source, we are effectively using the debug flag only in this middleware.

Any option to reconsider it?

We can wait for other people to share their thoughts here.

Also, we should invite @alex-oleshkevich to encode. cc @tomchristie

@alex-oleshkevich
Copy link
Member Author

I don't really see how it's counter-intuitive

I mean that Starlette supports error handlers, and you can define custom 500/Exception handler via error_handlers. But personally, I expect that the exception handler to be called always, and it is up to the user to determine what he wants to see when debug=True.

Losing priority would make people set the flag, and also comment the handlers.

In the current implementation, debug=True only affects exception page. This PR does the same but calls 500-handler (when available) instead of built-it and delegates debug argument to the handler.

I agree that this will break any existing user 500-handler as they don't handle debug and instead of exception page they will have their handler always called.

@euri10
Copy link
Member

euri10 commented Aug 12, 2022

yes I agree with @alex-oleshkevich and find that counter intuitive too

@Kludex
Copy link
Member

Kludex commented Sep 24, 2022

I've converted the issue into a discussion (#1867).

I think there's something we need to do regarding this, but we need to achieve consensus. Until then, I'll close this PR. 🙏

@Kludex Kludex closed this Sep 24, 2022
@alex-oleshkevich
Copy link
Member Author

As we head to 1.0 we may get back to this issue. My selling points are:

  1. an exception handler decides how to handle request.app.debug
  2. makes possible to integrate 3rd-party debug pages natively without middleware hack

@alex-oleshkevich alex-oleshkevich mentioned this pull request Oct 4, 2022
11 tasks
@Kludex Kludex reopened this Oct 4, 2022
@Kludex
Copy link
Member

Kludex commented Oct 4, 2022

Reopening for discussion. The previous arguments against are still too strong imo.

@euri10
Copy link
Member

euri10 commented Oct 4, 2022

Providing a better DX at a minor cost ie a breaking change for users who already have a 500 handlers is a no brainer to me, it should be done

@alex-oleshkevich
Copy link
Member Author

Closing it as it seems, this issue is not going to be addressed.
I monkey patch the ServerErrorMiddleware.debug_response overriding it with custom logic.
Hackish, but works.

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

Successfully merging this pull request may close these issues.

Custom error handler not called by ServerErrorMiddleware in debug mode
3 participants