From 8cf500ce44d545eaef1de6d509f0e7dac0cb6459 Mon Sep 17 00:00:00 2001 From: Salad Dais Date: Fri, 18 Apr 2025 01:42:09 +0000 Subject: [PATCH] Me more verbose if we can't parse legacy schema --- hippolyzer/lib/base/legacy_schema.py | 50 +++++++++++++++------------- hippolyzer/lib/base/serialization.py | 2 -- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/hippolyzer/lib/base/legacy_schema.py b/hippolyzer/lib/base/legacy_schema.py index b6b7da1..d878e6c 100644 --- a/hippolyzer/lib/base/legacy_schema.py +++ b/hippolyzer/lib/base/legacy_schema.py @@ -190,32 +190,36 @@ class SchemaBase(abc.ABC): def from_llsd(cls, inv_dict: Dict, flavor: str = "legacy"): fields = cls._get_fields_dict(llsd_flavor=flavor) obj_dict = {} - for key, val in inv_dict.items(): - if key in fields: - field: dataclasses.Field = fields[key] - key = field.name - spec = field.metadata.get("spec") - # Not a real key, an internal var on our dataclass - if not spec: - LOG.warning(f"Internal key {key!r}") - continue + try: + for key, val in inv_dict.items(): + if key in fields: + field: dataclasses.Field = fields[key] + key = field.name + spec = field.metadata.get("spec") + # Not a real key, an internal var on our dataclass + if not spec: + LOG.warning(f"Internal key {key!r}") + continue - spec_cls = spec - if not inspect.isclass(spec_cls): - spec_cls = spec_cls.__class__ + spec_cls = spec + if not inspect.isclass(spec_cls): + spec_cls = spec_cls.__class__ - # some kind of nested structure like sale_info - if issubclass(spec_cls, SchemaBase): - obj_dict[key] = spec.from_llsd(val, flavor) - elif issubclass(spec_cls, SchemaFieldSerializer): - obj_dict[key] = spec.from_llsd(val, flavor) + # some kind of nested structure like sale_info + if issubclass(spec_cls, SchemaBase): + obj_dict[key] = spec.from_llsd(val, flavor) + elif issubclass(spec_cls, SchemaFieldSerializer): + obj_dict[key] = spec.from_llsd(val, flavor) + else: + raise ValueError(f"Unsupported spec for {key!r}, {spec!r}") else: - raise ValueError(f"Unsupported spec for {key!r}, {spec!r}") - else: - if flavor != "ais": - # AIS has a number of different fields that are irrelevant depending on - # what exactly sent the payload - LOG.warning(f"Unknown key {key!r}") + if flavor != "ais": + # AIS has a number of different fields that are irrelevant depending on + # what exactly sent the payload + LOG.warning(f"Unknown key {key!r}") + except: + LOG.error(f"Failed to parse inventory schema: {inv_dict!r}") + raise return cls._obj_from_dict(obj_dict) def to_bytes(self) -> bytes: diff --git a/hippolyzer/lib/base/serialization.py b/hippolyzer/lib/base/serialization.py index f9f7374..54b5637 100644 --- a/hippolyzer/lib/base/serialization.py +++ b/hippolyzer/lib/base/serialization.py @@ -1728,7 +1728,6 @@ class QuantizedNumPyArray(Adapter): def subfield_serializer(msg_name, block_name, var_name): def f(orig_cls): - global SUBFIELD_SERIALIZERS SUBFIELD_SERIALIZERS[(msg_name, block_name, var_name)] = orig_cls return orig_cls return f @@ -1940,7 +1939,6 @@ class IntFlagSubfieldSerializer(AdapterInstanceSubfieldSerializer): def http_serializer(msg_name): def f(orig_cls): - global HTTP_SERIALIZERS HTTP_SERIALIZERS[msg_name] = orig_cls return orig_cls return f