state-machine-systems / JsonCodec

JSON combinator library for BuckleScript/Reason
Apache License 2.0
38 stars 7 forks source link

Document Error Reporting #22

Open bwestergard opened 6 years ago

bwestergard commented 6 years ago

First, thanks for all of your hard work on this.

Useful error messages are perhaps the most important feature of any serialization/deserialization framework. What sorts of errors does this library provide?

johnwright commented 6 years ago

Hi - at the moment, error reporting on decoding is very basic. You get a Result type with a string value describing the type of error, e.g. Expected boolean.

The next step would be to add the path to where the error was encountered (maybe with JsonPath notation), e.g. Expected boolean at $.foo.bar[2].baz.

This change should be reasonably straightforward, it involves threading path information through all decoding functions. Watch this space!

bwestergard commented 6 years ago

@johnwright Great! I was working on a similar project for Flow-typed javascript and settled on the JSONPointer standard. I think the ideal would be a Result<{message: string, pointer: Array<string | number>}>. The library could then provide a function to serialize the interal JsonPointer representation (Array<string | number>) as specified in RFC6901.

I'm an inexperienced OCaml developer. Perhaps I'll try to put together a PR.