From 993281882b2b76beb511aeb15334c18f71865207 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 30 May 2024 15:55:34 -0400 Subject: [PATCH] Pass `boxed_type` from `_mk_msg_type_err()` Such that we're boxing the interchanged lib's specific error `msgspec.ValidationError` in this case) type much like how a `ContextCancelled[trio.Cancelled]` is composed; allows for seemless multi-backend-codec support later as well B) Pass `ctx.maybe_raise(from_src_exc=src_err)` where needed in a couple spots; as `None` in the send-side `Started` MTE case to avoid showing the `._scope1.cancel_called` result in the traceback from the `.open_context()` child-sync phase. --- tractor/_exceptions.py | 8 ++++---- tractor/_streaming.py | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tractor/_exceptions.py b/tractor/_exceptions.py index 52048c1..92c3faf 100644 --- a/tractor/_exceptions.py +++ b/tractor/_exceptions.py @@ -518,7 +518,6 @@ class RemoteActorError(Exception): def pformat( self, with_type_header: bool = True, - # with_ascii_box: bool = True, ) -> str: ''' @@ -885,9 +884,9 @@ class MsgTypeError( extra_msgdata['_bad_msg'] = bad_msg extra_msgdata['cid'] = bad_msg.cid + extra_msgdata.setdefault('boxed_type', cls) return cls( message=message, - boxed_type=cls, **extra_msgdata, ) @@ -1111,7 +1110,7 @@ def is_multi_cancelled( def _raise_from_unexpected_msg( ctx: Context, msg: MsgType, - src_err: AttributeError, + src_err: Exception, log: StackLevelAdapter, # caller specific `log` obj expect_msg: Type[MsgType], @@ -1212,7 +1211,7 @@ def _raise_from_unexpected_msg( # in case there already is some underlying remote error # that arrived which is probably the source of this stream # closure - ctx.maybe_raise() + ctx.maybe_raise(from_src_exc=src_err) raise eoc from src_err # TODO: our own transport/IPC-broke error subtype? @@ -1361,6 +1360,7 @@ def _mk_msg_type_err( message=message, bad_msg=bad_msg, bad_msg_as_dict=msg_dict, + boxed_type=type(src_validation_error), # NOTE: for pld-spec MTEs we set the `._ipc_msg` manually: # - for the send-side `.started()` pld-validate diff --git a/tractor/_streaming.py b/tractor/_streaming.py index a008eaf..016577d 100644 --- a/tractor/_streaming.py +++ b/tractor/_streaming.py @@ -233,6 +233,7 @@ class MsgStream(trio.abc.Channel): # ctx: Context = self._ctx ctx.maybe_raise( raise_ctxc_from_self_call=True, + from_src_exc=src_err, ) # propagate any error but hide low-level frame details