Skip to content

Commit 8c8c524

Browse files
committed
Re-raise BuildError with traceback.
1 parent bb31188 commit 8c8c524

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

flask/app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,11 @@ def handle_build_error(self, error, endpoint, **values):
14901490
Calls :attr:`build_error_handler` if it is not `None`.
14911491
"""
14921492
if self.build_error_handler is None:
1493-
raise error
1493+
exc_type, exc_value, tb = sys.exc_info()
1494+
if exc_value is error:
1495+
raise exc_type, exc_value, tb
1496+
else:
1497+
raise error
14941498
return self.build_error_handler(error, endpoint, **values)
14951499

14961500
def preprocess_request(self):

flask/testsuite/basic.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,23 @@ def hello():
698698

699699
def test_build_error_handler(self):
700700
app = flask.Flask(__name__)
701+
702+
# Test base case, a URL which results in a BuildError.
701703
with app.test_request_context():
702704
self.assertRaises(BuildError, flask.url_for, 'spam')
705+
706+
# Verify the error is re-raised if not the current exception.
707+
try:
708+
with app.test_request_context():
709+
flask.url_for('spam')
710+
except BuildError, error:
711+
pass
712+
try:
713+
raise RuntimeError('Test case where BuildError is not current.')
714+
except RuntimeError:
715+
self.assertRaises(BuildError, app.handle_build_error, error, 'spam')
716+
717+
# Test a custom handler.
703718
def handler(error, endpoint, **values):
704719
# Just a test.
705720
return '/test_handler/'

0 commit comments

Comments
 (0)