From 95e8f3d3065f0d170bed3ab6de250d6fea3ab538 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 28 Oct 2019 00:47:06 -0400 Subject: [PATCH] Propagate `trio.MultiError`s up the actor tree `trio.MultiError` isn't an `Exception` (derived instead from `BaseException`) so we have to specially catch it in the task invocation machinery and ship it upwards (like regular errors) since nurseries running in sub-actors can raise them. --- tractor/_actor.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tractor/_actor.py b/tractor/_actor.py index 3f2a89c..c75647e 100644 --- a/tractor/_actor.py +++ b/tractor/_actor.py @@ -118,7 +118,7 @@ async def _invoke( with cancel_scope as cs: task_status.started(cs) await chan.send({'return': await coro, 'cid': cid}) - except Exception as err: + except (Exception, trio.MultiError) as err: # always ship errors back to caller log.exception("Actor errored:") err_msg = pack_error(err) @@ -352,7 +352,8 @@ class Actor: return cid, recv_chan async def _process_messages( - self, chan: Channel, + self, + chan: Channel, treat_as_gen: bool = False, shield: bool = False, task_status=trio.TASK_STATUS_IGNORED, @@ -461,7 +462,7 @@ class Actor: except trio.ClosedResourceError: log.error(f"{chan} form {chan.uid} broke") - except Exception as err: + except (Exception, trio.MultiError) as err: # ship any "internal" exception (i.e. one from internal machinery # not from an rpc task) to parent log.exception("Actor errored:") @@ -472,7 +473,7 @@ class Actor: # above to trigger an error at consuming portal "checkpoints" except trio.Cancelled: # debugging only - log.debug("Msg loop was cancelled") + log.debug(f"Msg loop was cancelled for {chan}") raise finally: log.debug(