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

Show path for schema errors #1

Merged
merged 1 commit into from
Nov 17, 2024
Merged

Conversation

sporto
Copy link
Contributor

@sporto sporto commented Nov 15, 2024

I tried decoding our schema.

And it fails with an error like

Error(UnexpectedFormat([DecodeError(expected: "another type", found: "Object", path: ["schemas",  "values"])]))

This is comming from the dictionary decoder, which doesn't give enough information about the value that is failing.

Our schema fails because some schema are missing the type property.
It is quite hard to figure out where as it is quite large.

This is an attempt at providing more information (they key of the dictionary that fails):

Error(UnexpectedFormat([DecodeError(expected: "another type", found: "Object", path: ["schemas",  "thing"])]))

@CrowdHailer
Copy link
Owner

CrowdHailer commented Nov 15, 2024

Should we make the suggestion that this is how dynamic.dict should work anyway?
I see the benefit and I like the test coverage, but I'm slight reluctant to support this patch to decoding.

@sporto
Copy link
Contributor Author

sporto commented Nov 16, 2024

I agree that the dynamic dict decoder should do something like this. I will look into it.
But that could take a while. In the meantime it would be great to have something here that can show an informative error.

@sporto
Copy link
Contributor Author

sporto commented Nov 16, 2024

Looking at std https://github.com/gleam-lang/stdlib/blob/main/src/gleam/dynamic.gleam#L968
It seems it will be much simpler to show the informative error there. So let's hold on this PR.

@sporto
Copy link
Contributor Author

sporto commented Nov 16, 2024

gleam-lang/stdlib#741

This will show values[index].
Not really possible to show the key name in the standard lib I think.

But we could do better here by showing the key name. As the key is a string.

@CrowdHailer
Copy link
Owner

alight lets go for it. thanks for the investigation

@CrowdHailer CrowdHailer merged commit f8d77a5 into CrowdHailer:main Nov 17, 2024
1 check passed
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