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

Better PlutusData Debug Messages on Error #266

Open
theeldermillenial opened this issue Jul 31, 2023 · 2 comments
Open

Better PlutusData Debug Messages on Error #266

theeldermillenial opened this issue Jul 31, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@theeldermillenial
Copy link
Contributor

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.

@cffls
Copy link
Collaborator

cffls commented 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
Copy link
Contributor Author

theeldermillenial commented Dec 30, 2023

Yes, and I use it extensively for XML parsing. pydantic has it's own dataclass that is designed to be a drop in replacement for dataclasses.dataclass, but I don't know how robust it is as a drop in replacement. I originally ran into pydantic 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/

@nielstron nielstron added the enhancement New feature or request label Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants