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 syntax errors #176

Merged
merged 7 commits into from
Apr 2, 2024
Merged

Better syntax errors #176

merged 7 commits into from
Apr 2, 2024

Conversation

timothee-haudebourg
Copy link
Collaborator

@timothee-haudebourg timothee-haudebourg commented Mar 28, 2024

Currently using serde to deserialize abstract layouts gives awful error messages when the layout definition is wrong. This PR uses the json_syntax::TryFromJsonSyntax trait that passes code mapping info to the deserializer to provide better syntax error messages.

Some examples of common errors, and the new message provided:

  • Missing required property:
error: Layout syntax error
  ┌─ layouts/examples/simple_record.json:6:9
  │  
6 │           "id": {
  │ ╭───────────────^
7 │ │             "intro": []
8 │ │         },
  │ ╰─────────^ missing required entry `value`
  • Invalid layout type:
error: Layout syntax error
  ┌─ layouts/examples/simple_record.json:3:10
  │
3 │     "type": "wrong",
  │             ^^^^^^^ invalid type value
  │
  = possible values are `id`, `unit`, `boolean`, `number`, `bytes`, `string`, `record`, `sum`, `list`, `set`, `tuple`, `union` and `intersection`
  = found type `wrong`
  • Duplicate entry:
error: Layout syntax error
  ┌─ layouts/examples/simple_record.json:3:2
  │
3 │     "type": "record",
  │     ^^^^^^ duplicate entry `type`
4 │     "type": "sum",
  │     ------ also defined here
  • Unexpected entry:
error: Layout syntax error
   ┌─ layouts/examples/simple_record.json:18:2
   │
18 │     "foo": "bar"
   │     ^^^^^ unexpected entry `foo`

@timothee-haudebourg timothee-haudebourg changed the title Better-syntax-errors Better syntaxerrors Mar 28, 2024
@timothee-haudebourg timothee-haudebourg changed the title Better syntaxerrors Better syntax errors Mar 28, 2024
@timothee-haudebourg timothee-haudebourg marked this pull request as ready for review April 2, 2024 12:34
@timothee-haudebourg timothee-haudebourg merged commit 9313354 into main Apr 2, 2024
2 checks passed
@timothee-haudebourg timothee-haudebourg deleted the better-syntax-errors branch April 2, 2024 13:42
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

Successfully merging this pull request may close these issues.

1 participant