Skip to content
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

Unify Json and ppx runtime modules #45

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

Unify Json and ppx runtime modules #45

wants to merge 7 commits into from

Conversation

andreypopp
Copy link
Collaborator

Ref: #36

@andreypopp andreypopp requested a review from jchavarri December 5, 2024 08:36
Copy link
Member

@anmonteiro anmonteiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ppx_deriving_json_runtime is still reading Json.Decode.error which seems to be gone?

@jchavarri jchavarri mentioned this pull request Dec 14, 2024
Copy link
Member

@jchavarri jchavarri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great @andreypopp !

I fixed the tests (don't ask how 🙈 ) in #46. For now I use the deprecated APIs (also helpful to see how users will have to adapt their code). Once they are removed we could update the tests to use the new APIs because they're quite exhaustive.

As can be seen in the PR, some of the JSON error messages were more detailed before. We should bring these details back somehow, do you think it'll be too hard with the PPX approach?

src/Json.mli Outdated
module Of_json : sig
(** Provides a set of low level combinator primitives to decode
Js.Json.t data structures A decoder combinator will return the
decoded value if successful, or raise a [DecodeError of string] if
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not DecodeError anymore.

(** JSON can be encoded as JSON, trivially. *)

(** The type of a error which occurs during decoding JSON values. *)
type of_json_error = Json_error of string | Unexpected_variant of string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected_variant currently always sends "unexpected variant" in the string payload. Should this payload be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've wanted to include the tag name there.

* main:
  update setup-ocaml
@jchavarri
Copy link
Member

I think #46 is ready:

  • updates error messages so they show the value received in the JSON, not only the failure
  • improve errors in some cases like objects with new information about which key is failing to be parsed
  • remove duplication in the browser ppx runtime code, reusing functions from Json module
  • remove DecodeError exn altogether to make sure that any code relying on it fails to compile, as it should use now Oj_json_error exn
  • fix ci tests
  • silence deprecation alerts in examples

Re: the last point, maybe we should update the examples code to use the new functions, but we can probably do that once they're removed completely?

If you think #46 is good to merge here, feel free to do so. The only things missing would be changelog entry and we should probably test some existing package or project that uses this library to make sure everything works as expected (melange-atdgen-codec-runtime is a good candidate).

@andreypopp
Copy link
Collaborator Author

@jchavarri thanks!

I've merged your PR and then removed ppx_deriving_runtime libs completely, instead melange-json and a (new) melange-json-native is used as runtime libs instead.

@jchavarri
Copy link
Member

Cool! I started taking a look at upgrading melange atdgen codec runtime, but it seems that library blended DecodeErrors from this lib with its own DecodeErrors instances 😕 so having a hard time fixing the tests. Will see if I can take another look this week and report back with more details about how the migration looks like from the user perspective.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants