routing: do not catch TypeError too wildly
The current scope if try/except it way larger than it needs to be, which could make it catch errors that are not tied to the method being called.
This commit is contained in:
@@ -173,15 +173,16 @@ def lookup_controller(obj, remainder, request=None):
|
|||||||
def handle_lookup_traversal(obj, args):
|
def handle_lookup_traversal(obj, args):
|
||||||
try:
|
try:
|
||||||
result = obj(*args)
|
result = obj(*args)
|
||||||
|
except TypeError as te:
|
||||||
|
logger.debug('Got exception calling lookup(): %s (%s)',
|
||||||
|
te, te.args)
|
||||||
|
else:
|
||||||
if result:
|
if result:
|
||||||
prev_obj = obj
|
prev_obj = obj
|
||||||
obj, remainder = result
|
obj, remainder = result
|
||||||
# crossing controller boundary
|
# crossing controller boundary
|
||||||
cross_boundary(prev_obj, obj)
|
cross_boundary(prev_obj, obj)
|
||||||
return result
|
return result
|
||||||
except TypeError as te:
|
|
||||||
logger.debug('Got exception calling lookup(): %s (%s)',
|
|
||||||
te, te.args)
|
|
||||||
|
|
||||||
|
|
||||||
def find_object(obj, remainder, notfound_handlers, request):
|
def find_object(obj, remainder, notfound_handlers, request):
|
||||||
|
|||||||
@@ -343,6 +343,17 @@ class TestLookups(PecanTestCase):
|
|||||||
r = app.get('/foo/bar', expect_errors=True)
|
r = app.get('/foo/bar', expect_errors=True)
|
||||||
assert r.status_int == 404
|
assert r.status_int == 404
|
||||||
|
|
||||||
|
def test_lookup_with_wrong_return(self):
|
||||||
|
class RootController(object):
|
||||||
|
@expose()
|
||||||
|
def _lookup(self, someID, *remainder):
|
||||||
|
return 1
|
||||||
|
|
||||||
|
app = TestApp(Pecan(RootController()))
|
||||||
|
self.assertRaises(TypeError,
|
||||||
|
app.get,
|
||||||
|
'/foo/bar', expect_errors=True)
|
||||||
|
|
||||||
|
|
||||||
class TestCanonicalLookups(PecanTestCase):
|
class TestCanonicalLookups(PecanTestCase):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user