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

Update of the manual to document error reporting #318

Merged
merged 4 commits into from
Jun 13, 2022

Conversation

panglesd
Copy link
Collaborator

This PR is part of the #314 tasks.

It adds a section about error reporting in the ppx for plugin authors section.

Note that it assumes that #316 has been merged, as it mentions the new API.

@panglesd
Copy link
Collaborator Author

I moved mention of raise_errorf and pxxlib's behavior wrt to it in a last paragraph, to make it clear that there is no real "choice" between embedding and raising: Embedding is the default, it has to be used (almost) always, raising is just in case of panicking. This was suggested by @pitag-ha in private communications.

@pitag-ha pitag-ha added the no changelog Use this label to disable the changelog check github action label Apr 20, 2022
Copy link
Member

@pitag-ha pitag-ha left a comment

Choose a reason for hiding this comment

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

Hey @panglesd, thanks for the section on error reporting, which is really needed! I haven't read it till the end yet, but I'm already leaving you some comments.

I think the beginning is very good! Then there comes a paragraph about whole-file transformations (see my comment below), then a paragraph about which I'm not sure if it's a summary or not (see my comment below), and then there come some sections that really go a lot into detail.

About the sections that go a lot into detail: what do you want the user to get out of them? And who's the target? (I myself can see different purposes for them, but I'm curious what the purpose was you had in mind when writing them)

Also, maybe the problem here is that the two of us just have very different writing/reading styles, so if you're very confident with how it is now, feel free to just merge it as is!

(Btw, I've only corrected the English of some paragraphs that stuck out to me. If you want, you could pass this through some grammar corrector (not necessary though).)

doc/ppx-for-plugin-authors.rst Outdated Show resolved Hide resolved
doc/ppx-for-plugin-authors.rst Outdated Show resolved Hide resolved
doc/ppx-for-plugin-authors.rst Outdated Show resolved Hide resolved
doc/ppx-for-plugin-authors.rst Outdated Show resolved Hide resolved
doc/ppx-for-plugin-authors.rst Outdated Show resolved Hide resolved
doc/ppx-for-plugin-authors.rst Outdated Show resolved Hide resolved
doc/ppx-for-plugin-authors.rst Outdated Show resolved Hide resolved
doc/ppx-for-plugin-authors.rst Outdated Show resolved Hide resolved
doc/ppx-for-plugin-authors.rst Outdated Show resolved Hide resolved
doc/ppx-for-plugin-authors.rst Outdated Show resolved Hide resolved
@panglesd
Copy link
Collaborator Author

Unfortunately, I think you have been reviewing an "rst comments" that is thus not included in the rendering of the manual...
That's mostly my fault, I should have removed this big comment that I mostly used as a draft area...
Sorry about that. The rst syntax for comments is not very explicit in my opinion...

Now that I have more confidence that #325 will be merged without deep modification, I think the best is that I rebase this PR on top of #325, migrate this section to odoc, implement your comments whenever they are not targeted to a "commented" part, and you resume your review from there?

In particular, I am not sure whether the comments about the structure still apply, without commented block!

Copy link
Member

@pitag-ha pitag-ha left a comment

Choose a reason for hiding this comment

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

Perfect, thanks a lot for the changes! I think it makes far clearer now how to report errors in a good way. I think it now has a very good balance between the important more or less high-level descriptions and just one low-level example.

My comments below are just suggestions, nothing important. For me, we can merge!

doc/manual.mld Outdated Show resolved Hide resolved
doc/manual.mld Outdated Show resolved Hide resolved
]}


When the record definition contains several fields with types other than [int], [float] or [string], several error nodes are added in the AST. Moreover, the location of the error nodes corresponds to the definition of the record fields. This allows tools such as Merlin to report all errors at once, at the right location, resulting in a better workflow than having to recompile everytime one error is corrected to see the next one.
Copy link
Member

Choose a reason for hiding this comment

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

That's interesting! That sounds like the only feature merlin loses when raising a located error instead of embedding the error is reporting multiple ppx errors. In fact, merlin looses all its features inside the context of a ppx, doesn't it? One of those features it looses of course is the reporting of more ppx errors, but others are jump-to-definition or show-definition-on-hover inside payloads etc, right? (this is just a side-note; no need to change anything)

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 would say that merlin does not lose those features as, with ppxlib 0.25, the last valid AST is kept when catching an exception, but I might not have understand exactly what you mean by "inside payloads"!

Copy link
Member

Choose a reason for hiding this comment

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

With "inside payload" I meant something like

let%my_ppx = <super long payload composed of lots of different value bindings etc
that, iiuc, don't have merlin features anymore if my_ppx raises>

But we can leave this sentence as is!

@panglesd
Copy link
Collaborator Author

panglesd commented Jun 3, 2022

I added a section explaining how to update a codebase to use the embedding error mechanism.

@pitag-ha
Copy link
Member

I added a section explaining how to update a codebase to use the embedding error mechanism.

Nice, thanks! Hopefully, that will convince even more people to improve their error reporting now.

It still all looks good to me. Let's merge this!

@pitag-ha
Copy link
Member

Oh wait, one thing I've just noticed: we could give this a changelog entry to give it more visibility. What do you think?

panglesd and others added 4 commits June 13, 2022 19:55
Signed-off-by: Paul-Elliot <peada@free.fr>
Signed-off-by: Paul-Elliot <peada@free.fr>
Co-authored-by: Sonja Heinze <sonjaleaheinze@gmail.com>
Signed-off-by: Paul-Elliot <peada@free.fr>
Signed-off-by: Paul-Elliot <peada@free.fr>
@pitag-ha pitag-ha merged commit 6471014 into ocaml-ppx:main Jun 13, 2022
pitag-ha added a commit to pitag-ha/opam-repository that referenced this pull request Jun 14, 2022
CHANGES:

- Update expansion context to leave out value name when multiple are
  defined at once. (ocaml-ppx/ppxlib#351, @ceastlund)

- Add support for OCaml 5.0 (ocaml-ppx/ppxlib#348, @pitag-ha)

- Add `Code_path.enclosing_value` (ocaml-ppx/ppxlib#349, @ceastlund)

- Add `Code_path.enclosing_module` (ocaml-ppx/ppxlib#346, @ceastlund)

- Expand code generated by `~enclose_intf` and `~enclose_impl` (ocaml-ppx/ppxlib#345, @ceastlund)

- Add type annotations to code generated by metaquot (ocaml-ppx/ppxlib#344, @ceastlund)

- Fix typo in description field of dune-project (ocaml-ppx/ppxlib#343, @ceastlund)

- Fix Ast_pattern.many (ocaml-ppx/ppxlib#333, @nojb)

- Fix quoter and optimize identifier quoting (ocaml-ppx/ppxlib#327, @sim642)

- Driver, when run with `--check`: Allow `toplevel_printer` attributes (ocaml-ppx/ppxlib#340, @pitag-ha)

- Documentation: Add a section on reporting errors by embedding extension nodes
  in the AST (ocaml-ppx/ppxlib#318, @panglesd)

- Driver: In the case of ppxlib internal errors, embed those errors instead of
  raising to return a meaningful AST (ocaml-ppx/ppxlib#329, @panglesd)

- API: For each function that could raise a located error, add a function that
  return a `result` instead (ocaml-ppx/ppxlib#329, @panglesd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog Use this label to disable the changelog check github action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants