forked from goodboy/tractor
1
0
Fork 0

Add `MsgTypeError.expected_msg_type`

Which matches with renaming `.payload_msg` -> `.expected_msg` which is
the value we attempt to construct from a vanilla-msgppack
decode-to-`dict` and then construct manually into a `MsgType` using
`.msg.types.from_dict_msg()`. Add a todo to use new `use_pretty` flag
which currently conflicts with `._exceptions.pformat_boxed_type()`
prefix formatting..
runtime_to_msgspec
Tyler Goodlet 2024-04-14 16:32:18 -04:00
parent 2d22713806
commit 2edfed75eb
1 changed files with 19 additions and 10 deletions

View File

@ -43,9 +43,12 @@ from tractor.msg import (
MsgType,
Stop,
Yield,
pretty_struct,
types as msgtypes,
)
from tractor.msg.pretty_struct import (
iter_fields,
Struct,
)
if TYPE_CHECKING:
from ._context import Context
@ -82,7 +85,7 @@ class InternalError(RuntimeError):
_ipcmsg_keys: list[str] = [
fi.name
for fi, k, v
in pretty_struct.iter_fields(Error)
in iter_fields(Error)
]
@ -321,7 +324,7 @@ class RemoteActorError(Exception):
assert self.boxed_type is boxed_type
@property
def ipc_msg(self) -> pretty_struct.Struct:
def ipc_msg(self) -> Struct:
'''
Re-render the underlying `._ipc_msg: Msg` as
a `pretty_struct.Struct` for introspection such that the
@ -334,12 +337,12 @@ class RemoteActorError(Exception):
msg_type: MsgType = type(self._ipc_msg)
fields: dict[str, Any] = {
k: v for _, k, v in
pretty_struct.iter_fields(self._ipc_msg)
iter_fields(self._ipc_msg)
}
return defstruct(
msg_type.__name__,
fields=fields.keys(),
bases=(msg_type, pretty_struct.Struct),
bases=(msg_type, Struct),
)(**fields)
@property
@ -641,11 +644,11 @@ class MsgTypeError(
'''
reprol_fields: list[str] = [
'payload_msg',
'expected_msg_type',
]
extra_body_fields: list[str] = [
'cid',
'payload_msg',
'expected_msg',
]
@property
@ -661,9 +664,7 @@ class MsgTypeError(
return self.msgdata.get('_msg_dict')
@property
def payload_msg(
self,
) -> MsgType|None:
def expected_msg(self) -> MsgType|None:
'''
Attempt to construct what would have been the original
`MsgType`-with-payload subtype (i.e. an instance from the set
@ -674,9 +675,17 @@ class MsgTypeError(
if msg_dict := self.msg_dict.copy():
return msgtypes.from_dict_msg(
dict_msg=msg_dict,
# use_pretty=True,
# ^-TODO-^ would luv to use this BUT then the
# `field_prefix` in `pformat_boxed_tb()` cucks it
# all up.. XD
)
return None
@property
def expected_msg_type(self) -> Type[MsgType]|None:
return type(self.expected_msg)
@property
def cid(self) -> str:
# pre-packed using `.from_decode()` constructor