Open psteckler opened 3 years ago
would it be possible to add a want_result
option like the want_exn
option in ppx_deriving_yojson
to generate decoders that return a result?
Would be nice if we could have an option to return a Result.t indeed.
For a type
t
, the ppx generates a valuet_of_yojson : Yojson.Safe.t -> t
. Hence, if the JSON doesn't correspond to at
instance, the decoder raises an exception (or has some undefined behavior).In
ppx_deriving_yojson
, the generated decoders produced aResult.t
, making it easy to know when there's an error.What is the reason to favor raising an exception, rather than revealing errors in the returned value?