-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
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
Fixed and intuitivized exception handling #1291
Conversation
This comment has been minimized.
This comment has been minimized.
@@ -62,6 +62,79 @@ def wrapper_func(self, *args, **kwargs): | |||
return update_wrapper(wrapper_func, f) | |||
|
|||
|
|||
def get_http_code(error_class_or_instance): |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
||
if is_code: | ||
# TODO: why is this? | ||
assert code != 500 or key is None, \ |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
16f0286
to
2977b77
Compare
:type code_or_exception: int|T<=Exception | ||
:type f: callable | ||
""" | ||
if isinstance(code_or_exception, HTTPException): # old broken behavior |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@flying-sheep This looks really good now BTW. |
|
||
exc_class, code = self._ensure_exc_class(code_or_exception) | ||
|
||
handlers = self.error_handler_spec.setdefault(key, {}).setdefault(code, {}) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
thanks! :D |
@flying-sheep Don't invest too much time in this yet, @mitsuhiko must decide this ultimatively. |
well, this is already discussed and implemented, everything that comes now is mere minutes of work, so i might as well. otherwise i trust mitsuhiko’s judgment except in the matter of Python 2 vs Python 3 ;) |
and regarding judgment: do you think the cleanness and neatness of grouping exception handlers using their http codes (or lack thereof) is worth the fact that it’s unnecessary for the logic? or not? |
I don't think it's worth it, but @mitsuhiko may come up with a reason why it is absolutely necessary (I've encountered such surprises before). |
can we now start the magic dance that summons him? |
I still don't know how that dance works. But I usually spam him on IRC regularly. |
@flying-sheep Would it be possible to fix #503 in the run? |
def find_superclass(d): | ||
if not d: | ||
return None | ||
for superclass in exc_class.mro(): |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Requesting help on reviewing this PR. I think it's a great change that definetly should land in 1.0. |
a174d23
to
eb2ca6d
Compare
btw. the regression test fails on master currently so i din’t break anything, i just rebased :) |
eb2ca6d
to
b31252d
Compare
It doesn't fail for me (I reverted the offending commit a while ago) |
oh, strange. it doesn’t fail on travis. wat. locally, so what did mitsuhiko say on IRC? you asking for reviews implies that he likes this? |
Hmm, how does #1407 behave for you then? |
so checkout unitaker/flask#no-threads and try? will do /e: still |
|
||
assert issubclass(exc_class, Exception) | ||
|
||
if issubclass(exc_class, HTTPException): |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
OK, so behavior-wise the current PR is excellent as-is. The only thing missing now are docs. From a quick glance at We also need something in |
writing something up right now, but |
We need to document how Flask prioritizes errorhandlers, doesn't matter where. |
Fixed and intuitivized exception handling
Thanks @flying-sheep! |
been a pleasure 😄 |
abandoning pull request #1281 for this.
the rationale for this is to
and all this while without breaking compatibility in not-already-broken usecases (which rely on the logic flaws i fixed)
TODO:
bake this into some tests as well
one error says
why is this?