forked from goodboy/tractor
1
0
Fork 0

Raise send-side MTEs inline in `PldRx.dec_msg()`

So when `is_started_send_side is True` we raise the newly created
`MsgTypeError` (MTE) directly instead of doing all the `Error`-msg pack
and unpack to raise stuff via `_raise_from_unexpected_msg()` since the
raise should happen send side anyway and so doesn't emulate any remote
fault like in a bad `Return` or `Started` without send-side pld-spec
validation.

Oh, and proxy-through the `hide_tb: bool` input from `.drain_to_final_msg()`
to `.recv_msg_w_pld()`.
runtime_to_msgspec
Tyler Goodlet 2024-05-28 15:52:54 -04:00
parent 59ca256183
commit a1b124b62b
1 changed files with 47 additions and 28 deletions

View File

@ -215,6 +215,9 @@ class PldRx(Struct):
**dec_msg_kwargs, **dec_msg_kwargs,
) )
# TODO: rename to,
# -[ ] `.decode_pld()`?
# -[ ] `.dec_pld()`?
def dec_msg( def dec_msg(
self, self,
msg: MsgType, msg: MsgType,
@ -248,8 +251,8 @@ class PldRx(Struct):
pld: PayloadT = self._pld_dec.decode(pld) pld: PayloadT = self._pld_dec.decode(pld)
log.runtime( log.runtime(
'Decoded msg payload\n\n' 'Decoded msg payload\n\n'
f'{msg}\n\n' f'{msg}\n'
f'where payload is\n' f'where payload decoded as\n'
f'|_pld={pld!r}\n' f'|_pld={pld!r}\n'
) )
return pld return pld
@ -265,13 +268,7 @@ class PldRx(Struct):
src_validation_error=valerr, src_validation_error=valerr,
is_invalid_payload=True, is_invalid_payload=True,
expected_msg=expect_msg, expected_msg=expect_msg,
# ipc_msg=msg,
) )
# NOTE: override the `msg` passed to
# `_raise_from_unexpected_msg()` (below) so so that
# we're effectively able to use that same func to
# unpack and raise an "emulated remote `Error`" of
# this local MTE.
err_msg: Error = pack_error( err_msg: Error = pack_error(
exc=mte, exc=mte,
cid=msg.cid, cid=msg.cid,
@ -283,34 +280,55 @@ class PldRx(Struct):
# tb=valerr.__traceback__, # tb=valerr.__traceback__,
tb_str=mte._message, tb_str=mte._message,
) )
# ^-TODO-^ just raise this inline instead of all the
# pack-unpack-repack non-sense!
mte._ipc_msg = err_msg mte._ipc_msg = err_msg
msg = err_msg
# set emulated remote error more-or-less as the # NOTE: just raise the MTE inline instead of all
# runtime would # the pack-unpack-repack non-sense when this is
ctx: Context = getattr(ipc, 'ctx', ipc) # a "send side" validation error.
if is_started_send_side:
raise mte
# XXX TODO: remove this right?
# => any bad stated/return values should
# always be treated a remote errors right?
#
# if (
# expect_msg is Return
# or expect_msg is Started
# ):
# # set emulated remote error more-or-less as the
# # runtime would
# ctx: Context = getattr(ipc, 'ctx', ipc)
# ctx._maybe_cancel_and_set_remote_error(mte)
# XXX override the `msg` passed to
# `_raise_from_unexpected_msg()` (below) so so
# that we're effectively able to use that same
# func to unpack and raise an "emulated remote
# `Error`" of this local MTE.
msg = err_msg
# XXX NOTE: so when the `_raise_from_unexpected_msg()`
# raises the boxed `err_msg` from above it raises
# it from the above caught interchange-lib
# validation error.
src_err = valerr
# TODO: should we instead make this explicit and # TODO: should we instead make this explicit and
# use the above masked `is_started_send_decode`, # use the above masked `is_started_send_decode`,
# expecting the `Context.started()` caller to set # expecting the `Context.started()` caller to set
# it? Rn this is kinda, howyousayyy, implicitly # it? Rn this is kinda, howyousayyy, implicitly
# edge-case-y.. # edge-case-y..
if ( # TODO: remove this since it's been added to
expect_msg is not Started # `_raise_from_unexpected_msg()`..?
and not is_started_send_side # if (
): # expect_msg is not Started
ctx._maybe_cancel_and_set_remote_error(mte) # and not is_started_send_side
# ):
# XXX NOTE: so when the `_raise_from_unexpected_msg()` # # set emulated remote error more-or-less as the
# raises the boxed `err_msg` from above it raises # # runtime would
# it from `None`. # ctx: Context = getattr(ipc, 'ctx', ipc)
src_err = valerr # ctx._maybe_cancel_and_set_remote_error(mte)
# if is_started_send_side:
# src_err = None
# XXX some other decoder specific failure? # XXX some other decoder specific failure?
# except TypeError as src_error: # except TypeError as src_error:
@ -561,6 +579,7 @@ async def drain_to_final_msg(
ipc=ctx, ipc=ctx,
expect_msg=Return, expect_msg=Return,
raise_error=False, raise_error=False,
hide_tb=hide_tb,
) )
# ^-TODO-^ some bad ideas? # ^-TODO-^ some bad ideas?
# -[ ] wrap final outcome .receive() in a scope so # -[ ] wrap final outcome .receive() in a scope so