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

feat: fromJson? derivations now say where a parsing error occurred #1656

Merged
merged 2 commits into from
Sep 28, 2022

Conversation

EdAyers
Copy link
Contributor

@EdAyers EdAyers commented Sep 27, 2022

Consider the following structures

structure Test1 where
  hello : String
  cheese? : Option Nat
  deriving ToJson, FromJson, Repr

structure Test2 where
  jam: Test1
  deriving ToJson, FromJson, Repr

#eval fromJson? (α := Test2) <| Json.mkObj [("jam", Json.mkObj [("hello", 4)])]

Previously, the expression in #eval would return an error "String expected". However often these parsing errors can occur in very deeply nested structures, making it hard to discover where exactly a string was inspected.

This PR causes the fromJson? method to prepend the field where the failure occurred if parsing fails. So now the above example will yield "Test2.jam: Test1.hello: String expected", making it clear that the badly formed sub-json was in jam.hello.

src/Lean/Elab/Deriving/FromToJson.lean Outdated Show resolved Hide resolved
@Kha Kha enabled auto-merge (squash) September 28, 2022 08:25
@Kha Kha merged commit 10971a4 into leanprover:master Sep 28, 2022
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.

2 participants