Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AeromancyStruct.validate needs better error messages #31

Open
dmcc opened this issue Jan 6, 2025 · 0 comments
Open

AeromancyStruct.validate needs better error messages #31

dmcc opened this issue Jan 6, 2025 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@dmcc
Copy link
Collaborator

dmcc commented Jan 6, 2025

[...]
src/colocation/colocation.py:29: in __init__
    self.metadata.validate()
.venv/lib/python3.10/site-packages/aeromancy/struct.py:87: in validate
    self.decode(self.encode(format="msgpack"), format="msgpack")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'colocation.structs.Metadata'>
encoded_bytes = b'\x83\xabinstruments\x9d\x91\x8d\xadinstrument_id\xa8ref-PM25\xafinstrument_type\x01\xa9pollutant\xa4pm25\xaftime_res...etary\xa4note\xc0\xa5parts\xc0\xa9num_parts\x01\xafgps_coordinates\x92\xcb@P6\x1f\xc8\xf3#y\xcb\xc0bwF\xf7\xa0\xb5\xee'
format = 'msgpack'

    @classmethod
    def decode(cls, encoded_bytes: bytes, format: str):
        """Deserialize this `msgspec.Struct` from bytes.
    
        Parameters
        ----------
        encoded_bytes
            Bytes to attempt to deserialize.
        format
            The format to used to encode the `msgspec.Struct`. This can be
            "yaml", "json", or "msgpack".
    
        Returns
        -------
        An instance of this class decoded according to `format`.
        """
        match format:
            case "yaml":
                return msgspec.yaml.decode(encoded_bytes, type=cls)
            case "json":
                return msgspec.json.decode(encoded_bytes, type=cls)
            case "msgpack":
>               return msgspec.msgpack.decode(encoded_bytes, type=cls)
E               msgspec.ValidationError: Expected `object`, got `array` - at `$.instruments[0]`

.venv/lib/python3.10/site-packages/aeromancy/struct.py:71: ValidationError

Catching and rethrowing the message with more details should help substantially.

@dmcc dmcc added enhancement New feature or request good first issue Good for newcomers labels Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant