JsonCodec icon indicating copy to clipboard operation
JsonCodec copied to clipboard

Document Error Reporting

Open bwestergard opened this issue 7 years ago • 2 comments

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?

bwestergard avatar Jun 06 '18 20:06 bwestergard

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!

johnwright avatar Jun 07 '18 00:06 johnwright

@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.

bwestergard avatar Jun 07 '18 18:06 bwestergard