Let `pack_error()` take a msg injected `cid: str|None`

modden_spawn_from_client_req
Tyler Goodlet 2024-02-18 17:17:31 -05:00
parent 7fbada8a15
commit 7f29fd8dcf
1 changed files with 16 additions and 10 deletions

View File

@ -163,13 +163,15 @@ class MessagingError(Exception):
def pack_error( def pack_error(
exc: BaseException, exc: BaseException,
tb: str | None = None, tb: str|None = None,
cid: str|None = None,
) -> dict[str, dict]: ) -> dict[str, dict]:
''' '''
Create an "error message" encoded for wire transport via an IPC Create an "error message" which boxes a locally caught
`Channel`; expected to be unpacked on the receiver side using exception's meta-data and encodes it for wire transport via an
`unpack_error()` below. IPC `Channel`; expected to be unpacked (and thus unboxed) on
the receiver side using `unpack_error()` below.
''' '''
if tb: if tb:
@ -197,7 +199,12 @@ def pack_error(
): ):
error_msg.update(exc.msgdata) error_msg.update(exc.msgdata)
return {'error': error_msg}
pkt: dict = {'error': error_msg}
if cid:
pkt['cid'] = cid
return pkt
def unpack_error( def unpack_error(
@ -207,7 +214,7 @@ def unpack_error(
err_type=RemoteActorError, err_type=RemoteActorError,
hide_tb: bool = True, hide_tb: bool = True,
) -> None | Exception: ) -> None|Exception:
''' '''
Unpack an 'error' message from the wire Unpack an 'error' message from the wire
into a local `RemoteActorError` (subtype). into a local `RemoteActorError` (subtype).
@ -358,8 +365,7 @@ def _raise_from_no_key_in_msg(
# is activated above. # is activated above.
_type: str = 'Stream' if stream else 'Context' _type: str = 'Stream' if stream else 'Context'
raise MessagingError( raise MessagingError(
f'{_type} was expecting a `{expect_key}` message' f"{_type} was expecting a '{expect_key}' message"
' BUT received a non-`error` msg:\n' " BUT received a non-error msg:\n"
f'cid: {cid}\n' f'{pformat(msg)}'
'{pformat(msg)}'
) from src_err ) from src_err