Extend recv-side `MsgTypeError` default message
Display the new `MsgCodec.pld_spec_str` and format the incorrect field value to be placed entirely (txt block wise) right of the "type annot" part of the line: Iow if you had a bad `dict` value where something else should be it'd look something like this: <Started( |_pld: NamespacePath = {'cid': '3e0ca00c-7d32-4d2a-a0c2-ac2e12453871', 'locked': True, 'msg_type': 'LockStatus', 'subactor_uid': ['sub', 'af7ccb69-1dab-491f-84f7-2ec42c32d137']}runtime_to_msgspec
parent
faa7194daf
commit
3fb3608879
|
@ -130,6 +130,8 @@ def _mk_msg_type_err(
|
||||||
|
|
||||||
) -> MsgTypeError:
|
) -> MsgTypeError:
|
||||||
|
|
||||||
|
import textwrap
|
||||||
|
|
||||||
# `Channel.send()` case
|
# `Channel.send()` case
|
||||||
if src_validation_error is None: # send-side
|
if src_validation_error is None: # send-side
|
||||||
|
|
||||||
|
@ -209,10 +211,24 @@ def _mk_msg_type_err(
|
||||||
msg, _, maybe_field = msgspec_msg.rpartition('$.')
|
msg, _, maybe_field = msgspec_msg.rpartition('$.')
|
||||||
obj = object()
|
obj = object()
|
||||||
if (field_val := msg_dict.get(maybe_field, obj)) is not obj:
|
if (field_val := msg_dict.get(maybe_field, obj)) is not obj:
|
||||||
|
field_name_expr: str = (
|
||||||
|
f' |_{maybe_field}: {codec.pld_spec_str} = '
|
||||||
|
)
|
||||||
|
fmt_val_lines: list[str] = pformat(field_val).splitlines()
|
||||||
|
fmt_val: str = (
|
||||||
|
f'{fmt_val_lines[0]}\n'
|
||||||
|
+
|
||||||
|
textwrap.indent(
|
||||||
|
'\n'.join(fmt_val_lines[1:]),
|
||||||
|
prefix=' '*len(field_name_expr),
|
||||||
|
)
|
||||||
|
)
|
||||||
message += (
|
message += (
|
||||||
f'{msg.rstrip("`")}\n\n'
|
f'{msg.rstrip("`")}\n\n'
|
||||||
f'{msg_type}\n'
|
f'<{msg_type.__qualname__}(\n'
|
||||||
f' |_.{maybe_field}: {codec.pld_spec_str} = {field_val!r}\n'
|
# f'{".".join([msg_type.__module__, msg_type.__qualname__])}\n'
|
||||||
|
f'{field_name_expr}{fmt_val}\n'
|
||||||
|
f')>'
|
||||||
)
|
)
|
||||||
|
|
||||||
msgtyperr = MsgTypeError.from_decode(
|
msgtyperr = MsgTypeError.from_decode(
|
||||||
|
@ -338,7 +354,7 @@ class MsgpackTCPStream(MsgTransport):
|
||||||
# self._task = task
|
# self._task = task
|
||||||
self._codec = codec
|
self._codec = codec
|
||||||
log.runtime(
|
log.runtime(
|
||||||
'Using new codec in {self}.recv()\n'
|
f'Using new codec in {self}.recv()\n'
|
||||||
f'codec: {self._codec}\n\n'
|
f'codec: {self._codec}\n\n'
|
||||||
f'msg_bytes: {msg_bytes}\n'
|
f'msg_bytes: {msg_bytes}\n'
|
||||||
)
|
)
|
||||||
|
@ -420,7 +436,7 @@ class MsgpackTCPStream(MsgTransport):
|
||||||
if self._codec.pld_spec != codec.pld_spec:
|
if self._codec.pld_spec != codec.pld_spec:
|
||||||
self._codec = codec
|
self._codec = codec
|
||||||
log.runtime(
|
log.runtime(
|
||||||
'Using new codec in {self}.send()\n'
|
f'Using new codec in {self}.send()\n'
|
||||||
f'codec: {self._codec}\n\n'
|
f'codec: {self._codec}\n\n'
|
||||||
f'msg: {msg}\n'
|
f'msg: {msg}\n'
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue