-
Notifications
You must be signed in to change notification settings - Fork 132
Improve JSON/YAML parsing errors #1090
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
Comments
I'll first note that we are using Now - I thought about switching JSON library to improve error messages, but I'm not convinced this move would buy us much? To sum up: I am not opposed to switching to something better, but I'd like to see us try to improve things with the current library first, and if these attempts look like failures then the new thing should have some clear way to address them. |
Makes sense. I think a custom |
I think we'll need both (the matching, and the custom printer) to handle this stuff. E.g. for #1057, we get this
That's a If we'd match on the Then I think #1086 is a little harder - we get a cryptic
This is not legible for two reasons (as @finnhodgkin noted):
I think for (1) we could wrap the parse error in a I wonder if @garyb or @thomashoneyman have any insight on this? |
Hmm... to accumulate the errors you'd have to write a manual codec that tries both branches and then checks if they both fail, and if so constructs a new error message. Even after that, with the current structure of the error message type there's not really a good fit for the constructor that message would go into unfortunately. Re-error-typing the codecs is possible, but it would mean essentially reimplementing them all, or having to call a wrapper function around them all to make them compatible. I do intend to change things a little bit for the I've been working on my house lately so the JSON stuff has been on the backburner, but if it's something that you're interested in I could set aside some time this weekend to wrap that up instead. |
PackageName is a newtype around string. So can we use our own codec for that? Something like |
The error swallowing in question is due to the |
That would be lovely! ❤️ Wish I could lend you a hand on the house works 😄 |
It lives: https://github.com/garyb/purescript-codec-json There are some changes from
The revised error structure I mentioned ended up gaining a little more complexity than my "just path + message" proposal, there's also a "causes" that allows errors to be given context (like type names, or when grouping errors for failed alternatives). Here's an example of the kind of thing it prints for an error now where I used
The setup that produces that is in the tests. The Let me know what you think! |
Thanks @garyb, this looks great! ❤️ |
I'm on board. Can do a review of the registry codecs and update their errors after I finish a couple other things, unless this is urgent. |
Ah yeah, I was thinking I might add a |
|
👍 exactly what I had in mind! |
I've pushed a new version with that added now. |
I have this almost ready, with patches for codec-json, the registry, and spago itself |
Uh oh!
There was an error while loading. Please reload this page.
See #1057 and #1086 for context.
json-codecs
(in its current latest version, which is not the same version of the library used bylanguage-purescript
at the moment) differs fromcodec-argonaut
/argonaut-codec
in the following ways:JsonDecodeError
codec-arognaut
supports this but notargonaut-codec
) using record syntaxargonaut-codec
but similar tocodec-argonaut
, it's value-based codecscodec-argonaut
, but I could add bidirectional codecsSee the test code and its current output
The library isn't the most well-tested it could be (e.g. are the otherwise unidirectional encoder/decoders for a given type actually bidirectional if used together). But would there be interest in this?
The text was updated successfully, but these errors were encountered: