Skip to content

Commit

Permalink
Re-raise BuildError with traceback.
Browse files Browse the repository at this point in the history
  • Loading branch information
rduplain committed Apr 22, 2012
1 parent bb31188 commit 8c8c524
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,11 @@ def handle_build_error(self, error, endpoint, **values):
Calls :attr:`build_error_handler` if it is not `None`.
"""
if self.build_error_handler is None:
raise error
exc_type, exc_value, tb = sys.exc_info()
if exc_value is error:
raise exc_type, exc_value, tb
else:
raise error
return self.build_error_handler(error, endpoint, **values)

def preprocess_request(self):
Expand Down
15 changes: 15 additions & 0 deletions flask/testsuite/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,23 @@ def hello():

def test_build_error_handler(self):
app = flask.Flask(__name__)

# Test base case, a URL which results in a BuildError.
with app.test_request_context():
self.assertRaises(BuildError, flask.url_for, 'spam')

# Verify the error is re-raised if not the current exception.
try:
with app.test_request_context():
flask.url_for('spam')
except BuildError, error:
pass
try:
raise RuntimeError('Test case where BuildError is not current.')
except RuntimeError:
self.assertRaises(BuildError, app.handle_build_error, error, 'spam')

# Test a custom handler.
def handler(error, endpoint, **values):
# Just a test.
return '/test_handler/'
Expand Down

0 comments on commit 8c8c524

Please sign in to comment.