Skip to content
Myr

Handle empty deque on errorhandler lookup.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

After registering a custom errorhandler by exception class, raising any unhandled exception in a view function swallows the error and instead throws an `IndexError` on trying to look up the appropriate handler. This patch avoids the uninformative `IndexError` and preserves the original exception by looping until the deque of classes is empty, not forever.

authored by Joshua Carp · committed by Joshua Carp · parent 0d19fa0 · Browse files · 2 files+30 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+30 added−1 removed

  • tests:+29 added−0 removed
  • other:+1 added−1 removed

2 files+30 added−1 removed

modified:flask/app.py+1 added-1 removed
1419 unmodified lines
1420 # Protect from geniuses who might create circular references in1421 # __mro__1422 done = set()14231424 while True:1424 while queue:1425 cls = queue.popleft()1426 if cls in done:1427 continue1428 done.add(cls)
548 unmodified lines
modified:tests/test_user_error_handler.py+29 added
1 unmodified line
2from werkzeug.exceptions import Forbidden, InternalServerError3import flask456def test_error_handler_no_match():7 app = flask.Flask(__name__)89 class CustomException(Exception):10 pass1112 @app.errorhandler(CustomException)13 def custom_exception_handler(e):14 assert isinstance(e, CustomException)15 return 'custom'1617 @app.errorhandler(500)18 def handle_500(e):19 return type(e).__name__2021 @app.route('/custom')22 def custom_test():23 raise CustomException()2425 @app.route('/keyerror')26 def key_error():27 raise KeyError()2829 c = app.test_client()3031 assert c.get('/custom').data == b'custom'32 assert c.get('/keyerror').data == b'KeyError'333435def test_error_handler_subclass():36 app = flask.Flask(__name__)3738 class ParentException(Exception):
102 unmodified lines