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

Fixed and intuitivized exception handling #1291

Merged
merged 8 commits into from
Apr 11, 2015

Conversation

flying-sheep
Copy link
Contributor

abandoning pull request #1281 for this.

the rationale for this is to

  1. fix some logic flaws
  2. make errorhandlers more intuitive by making them rely on exception hierarchy instead of registration order
  3. Enable 500 handlers on blueprint level

and all this while without breaking compatibility in not-already-broken usecases (which rely on the logic flaws i fixed)

TODO:

  1. bake this into some tests as well

  2. one error says

    It is currently not possible to register a 500 internal server error on a per-blueprint level.

    why is this?

@flying-sheep

This comment has been minimized.

@untitaker untitaker added this to the 1.0 milestone Dec 23, 2014
@@ -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.

This comment was marked as off-topic.

@danielchatfield

This comment has been minimized.

@flying-sheep

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.

@flying-sheep flying-sheep force-pushed the errorhandler-rework branch 3 times, most recently from 16f0286 to 2977b77 Compare December 28, 2014 15:22
: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.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@untitaker
Copy link
Contributor

@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.

This comment was marked as off-topic.

@flying-sheep
Copy link
Contributor Author

@flying-sheep This looks really good now BTW.

thanks! :D

@untitaker
Copy link
Contributor

@flying-sheep Don't invest too much time in this yet, @mitsuhiko must decide this ultimatively.

@flying-sheep
Copy link
Contributor Author

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 ;)

@flying-sheep
Copy link
Contributor Author

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?

@untitaker
Copy link
Contributor

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).

@flying-sheep
Copy link
Contributor Author

can we now start the magic dance that summons him?

@untitaker
Copy link
Contributor

I still don't know how that dance works. But I usually spam him on IRC regularly.

@untitaker
Copy link
Contributor

@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.

@untitaker
Copy link
Contributor

Requesting help on reviewing this PR. I think it's a great change that definetly should land in 1.0.

@flying-sheep
Copy link
Contributor Author

btw. the regression test fails on master currently so i din’t break anything, i just rebased :)

@untitaker
Copy link
Contributor

btw. the regression test fails on master currently so i din’t break anything, i just rebased :)

It doesn't fail for me (I reverted the offending commit a while ago)

@flying-sheep
Copy link
Contributor Author

oh, strange. it doesn’t fail on travis. wat.

locally, test_memory_consumption fails.

so what did mitsuhiko say on IRC? you asking for reviews implies that he likes this?

@untitaker
Copy link
Contributor

Hmm, how does #1407 behave for you then?

@flying-sheep
Copy link
Contributor Author

so checkout unitaker/flask#no-threads and try? will do

/e: still test_regression.assert_no_leak fails


assert issubclass(exc_class, Exception)

if issubclass(exc_class, HTTPException):

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@untitaker
Copy link
Contributor

OK, so behavior-wise the current PR is excellent as-is.

The only thing missing now are docs. From a quick glance at errorhandling.rst there doesn't seem to be anything contradictory in there, but we should definetly clarify the current behavior.

We also need something in upgrading.rst, and a changelog entry.

@flying-sheep
Copy link
Contributor Author

writing something up right now, but errorhandling.rst doesn’t seem to contain anything about error handlers, only logging and debugging AFAICS

@untitaker
Copy link
Contributor

We need to document how Flask prioritizes errorhandlers, doesn't matter where. errorhandling seemed like the most related page to me.

untitaker added a commit that referenced this pull request Apr 11, 2015
Fixed and intuitivized exception handling
@untitaker untitaker merged commit aed464b into pallets:master Apr 11, 2015
@flying-sheep flying-sheep deleted the errorhandler-rework branch April 11, 2015 16:14
@untitaker
Copy link
Contributor

Thanks @flying-sheep!

@untitaker untitaker mentioned this pull request Apr 11, 2015
6 tasks
@flying-sheep
Copy link
Contributor Author

been a pleasure 😄

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.

5 participants