Skip to content

Don't pass unexpected exception types to error handlers - #2983

Closed
taion wants to merge 2 commits into
pallets:masterfrom
taion:handle-internal-server-error
Closed

taion wants to merge 2 commits into
pallets:masterfrom
taion:handle-internal-server-error

Conversation

@taion

@taion taion commented Nov 1, 2018

Copy link
Copy Markdown
Contributor

Fixes #2778

cc @ThiefMaster

This follows my last proposal in #2778 (comment).

@garenchan

Copy link
Copy Markdown
Contributor

Like you, I think the current implementation is a bit confusing.

But at least we can get the original error in the handler. This is useful for both logging and troubleshooting errors. But your solution doesn't take this into account.

@taion

taion commented Nov 12, 2018

Copy link
Copy Markdown
Contributor Author

Perhaps InternalServerError should be tagged with the original error.

Note, though, that the implementation above will forward the original error when the error handler is installed on 500.

@garenchan

garenchan commented Nov 12, 2018 •

Copy link
Copy Markdown
Contributor

I'm sorry to have misunderstood your solution. I think a test case for the handler of InternalServerError can help us understand your solution more easily.

@taion

taion commented Nov 12, 2018

Copy link
Copy Markdown
Contributor Author

This assertion is actually already present in

assert client.get('/keyerror').data == b'KeyError'
.

@garenchan

Copy link
Copy Markdown
Contributor

Oh, I see. I only read the codes in your patch. Please forgive me for wasting your precious time!

@taion

taion commented Nov 12, 2018

Copy link
Copy Markdown
Contributor Author

I mean, now that you mention it, though, I do think it would be a better API if InternalServerError had some reference to the actual original exception. That would likely constitute a breaking API change, though, whereas this might just barely be okay.

@garenchan

Copy link
Copy Markdown
Contributor

Yes, I quite agree with you.

Perhaps InternalServerError should be tagged with the original error.

@taion

This comment has been minimized.

@davidism

davidism commented Jun 19, 2019 •

Copy link
Copy Markdown
Member

While I understand the results of this, it's making the code harder to follow for me. Based on previous discussions in PRs that led to where we are now, it seems that it was intended that 500 and InternalServerError were aliases that behave the same way.

Instead, based on your discussions, I went the other direction and made it consistent. 500 and InternalServerError handlers always received InternalServerError, and also add an original_exception attribute. While this could result in some less-specific generic error messages if an application with the old behavior upgrades, I think the behavior becoming easier to reason about is worth it.

Thanks for discussing and working on this! Closing in favor of #3266

@davidism davidism closed this Jun 19, 2019
@taion
taion deleted the handle-internal-server-error branch June 21, 2019 02:38
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Registered error handler (using register_error_handler) processes inappropriate exceptions

4 participants