diff --git a/tests/functional/single_server/client_test.py b/tests/functional/single_server/client_test.py index 6ebae70..125eec4 100644 --- a/tests/functional/single_server/client_test.py +++ b/tests/functional/single_server/client_test.py @@ -43,8 +43,11 @@ async def divide(semaphore, req): def test_server_error(): client = ZeroClient(server.HOST, server.PORT) - msg = client.call("error", "some error") - assert msg is None + try: + msg = client.call("error", "some error") + raise AssertionError("Should have thrown an Exception") + except zero.error.RemoteException: + pass def test_default_timeout(): diff --git a/zero/client_server/client.py b/zero/client_server/client.py index f19f3ca..ad80674 100644 --- a/zero/client_server/client.py +++ b/zero/client_server/client.py @@ -4,11 +4,17 @@ from zero import config from zero.encoder import Encoder, get_encoder -from zero.error import MethodNotFoundException, TimeoutException +from zero.error import MethodNotFoundException, TimeoutException, RemoteException from zero.utils.util import current_time_us, unique_id from zero.zero_mq import AsyncZeroMQClient, ZeroMQClient, get_async_client, get_client from zero.zero_mq.helpers import zpipe_async +def check_response(resp_data): + if isinstance(resp_data, dict): + if e := resp_data.get("__zerror__method_not_found"): + raise MethodNotFoundException(e) + if e := resp_data.get("__zerror__server_exception"): + raise RemoteException(e) class ZeroClient: def __init__( @@ -101,8 +107,7 @@ def _poll_data(): while resp_id != req_id: resp_id, resp_data = _poll_data() - if isinstance(resp_data, dict) and "__zerror__method_not_found" in resp_data: - raise MethodNotFoundException(resp_data.get("__zerror__method_not_found")) + check_response(resp_data) return resp_data @@ -237,7 +242,6 @@ async def _poll_data(): resp_data = self._resp_map.pop(req_id) - if isinstance(resp_data, dict) and "__zerror__method_not_found" in resp_data: - raise MethodNotFoundException(resp_data.get("__zerror__method_not_found")) + check_response(resp_data) return resp_data diff --git a/zero/client_server/worker.py b/zero/client_server/worker.py index 17e88e3..8f41489 100644 --- a/zero/client_server/worker.py +++ b/zero/client_server/worker.py @@ -104,6 +104,7 @@ def handle_msg(self, rpc, msg): except Exception as exc: logging.exception(exc) + ret = {"__zerror__server_exception": repr(exc)} return ret diff --git a/zero/error.py b/zero/error.py index 2c2fda6..f0f8b4c 100644 --- a/zero/error.py +++ b/zero/error.py @@ -12,3 +12,6 @@ class TimeoutException(ZeroException): class ConnectionException(ZeroException): pass + +class RemoteException(Exception): + pass