forked from goodboy/tractor
Let `pack_error()` take a msg injected `cid: str|None`
parent
7fbada8a15
commit
7f29fd8dcf
|
@ -164,12 +164,14 @@ 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(
|
||||||
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue