- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 78
Description
Is your feature request related to a problem? Please describe.
When ingesting raw plutus data in some form, if the structure is complicated the error messages can be unclear about where in the data structure the error is being thrown.
For example, if there is an incorrect CONSTR_ID
, you get an error message saying something like:
pycardano.exception.DeserializeException: Mismatch between constructors, expect: 0, got: 1 instead.
This doesn't tell me where the constructor error is occurring. Hopefully I don't have too many 1's in my data structure.
Describe the solution you'd like
Ideally when either serializing or deserializing, errors would have some form of data structure "stack trace" for lack of a better word. An example of how this has been handled well is in pydantic.
One potential (heavy lift) implementation of this would be to rewrite the underlying PlutusData classes to use pydantic. Maybe a less heavy lift would be to use the pydantic dataclasses, and honestly, it might be as simple as using pydantic dataclasses for the decorators rather than the vanilla base dataclasses.
Activity
cffls commentedon Dec 29, 2023
Added class name to the exception in this PR #288
Hope it will help.
Interesting idea of using pydantic. Do you know if it is fully compatible with python's vanilla dataclasses?
theeldermillenial commentedon Dec 30, 2023
Yes, and I use it extensively for XML parsing.
pydantic
has it's owndataclass
that is designed to be a drop in replacement fordataclasses.dataclass
, but I don't know how robust it is as a drop in replacement. I originally ran intopydantic
when building APIs, but I use it in nearly all my work. It's especially useful when building API clients to validate the response values. There are also a LOT of tools out there to autogenerate pydantic BaseModel/dataclass objects from schema (XML schema, openAPI, etc).https://docs.pydantic.dev/latest/concepts/dataclasses/