Skip to content

Better PlutusData Debug Messages on Error #266

@theeldermillenial

Description

@theeldermillenial
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.

Activity

cffls

cffls commented on Dec 29, 2023

@cffls
Collaborator

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

theeldermillenial commented on Dec 30, 2023

@theeldermillenial
ContributorAuthor

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nielstron@cffls@theeldermillenial

        Issue actions

          Better PlutusData Debug Messages on Error · Issue #266 · Python-Cardano/pycardano