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
of_yojson_exn breaks code that defines of/to_yojson by hand #76
Comments
I think the right path here is to make the feature opt-in, not revert. Opinions @ocaml-ppx/deriving? |
To make this feature play nice with existing code, we could also always use |
I agree that this is better. |
fixes ocaml-ppx#76 Adding new functions to the default generated interface (and signature) is problematic for user code that uses [@@deriving yojson] in signatures, but manually implements the two `{of,to}_yojson` functions (and nothing else) in their implementations. There is plenty of code in this style in OPAM.
I'm commenting a bit late on the issue, but adding
of_yojson_exn
(see #68) breaks all code that definesof_yojson
by hand ([@@deriving of_yojson]
in the mli,let of_yojson
in the ml).This means that to support this, users will have to copy/paste
let of_yojson_exn json = match of_yojson json with Ok x -> x | Error e -> failwith e
or similar. It would be nice ifppx_deriving_yojson
could handle these cases automatically, but it's unfortunately not possible.I suggest that we revert this part before the next release and advise users to use a combinator like
CCResult.get_exn
orRResult.R.get_ok
. An alternative is to make this feature opt-in: for example if[@@deriving yojson { exn = true }]
is present, generate theof_yojson_exn
function in the .ml, and add the correspondingval
in the .mli.Thanks!
The text was updated successfully, but these errors were encountered: