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

Flatten error messages #10

Open
drhagen opened this issue Jan 31, 2024 · 0 comments
Open

Flatten error messages #10

drhagen opened this issue Jan 31, 2024 · 0 comments

Comments

@drhagen
Copy link
Owner

drhagen commented Jan 31, 2024

I have come to like the the flattened nature of the errors in Pydantic. The use of loc instead of nested maps works better in the face of lists, whose keys are integers and cannot be put into JSON objects without being stringified. The data structure also allows for more information to be returned other than the message, which is a good thing.

I am thinking a data structure like this would be good for DeserializationErrors to serialize into:

[
  {
    "location": ["models", 5],
    "type": "ModelNotFoundError",
    "context": {
      "actual": "mouse_pk"
    },
    "message": "Model 'mouse_pk' not found"
  },
  {
    "location": ["data", 101, "measurement_unit"],
    "type": "ParseError",
    "context": {
      "line": 1,
      "character": 4,
      "expected": ["r'[A-Za-z]+'"],
    },
    "message": "Expected r'[A-Za-z]+' but found '/'\nLine 1, character 4\n\nmg//kg\n   ^"
  }
]

At the same time, DeserializationError should either gain lots of functionality to assist with building errors or there should be a Builder class that assists with this and can be converted to a DeserializationError.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant