Skip to content

Commit

Permalink
Don't try to translate aiosfstream exceptions
Browse files Browse the repository at this point in the history
The translate_errors_context context manager, which is responsible
for translating aiocometd exceptions to their aiosfstream
counterparts, caught aiosfstream exceptions as well and tried to
translate them, resulting in a KeyError.
Catch the aiosfstream exceptions and let them pass through before
aiocometd exception types are considered.
  • Loading branch information
robertmrk committed Nov 7, 2018
1 parent ae7d375 commit 4991751
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions aiosfstream/exceptions.py
Expand Up @@ -106,6 +106,8 @@ def translate_errors_context():
"""
try:
yield
except AiosfstreamException:
raise
except cometd_exc.AiocometdException as cometd_error:
error_cls = EXCEPTION_PAIRS[type(cometd_error)]
raise error_cls(*cometd_error.args) from cometd_error
Expand Down
28 changes: 28 additions & 0 deletions tests/test_exceptions.py
Expand Up @@ -118,3 +118,31 @@ async def raise_error():
await exc.translate_errors(raise_error)()

self.assertEqual(cm.exception.args, error.args)

def test_reraises_sfstream_error(self):
response = {
"error": "400:arg1,arg2:description"
}
error = exc.ServerError("Message", response)

def raise_error():
raise error

with self.assertRaises(exc.ServerError) as cm:
exc.translate_errors(raise_error)()

self.assertEqual(cm.exception.args, error.args)

async def test_async_reraises_sfstream_error(self):
response = {
"error": "400:arg1,arg2:description"
}
error = exc.ServerError("Message", response)

async def raise_error():
raise error

with self.assertRaises(exc.ServerError) as cm:
await exc.translate_errors(raise_error)()

self.assertEqual(cm.exception.args, error.args)

0 comments on commit 4991751

Please sign in to comment.