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

Option to turn warnings into errors #398

Merged
merged 5 commits into from
Dec 4, 2019
Merged

Conversation

Julow
Copy link
Collaborator

@Julow Julow commented Nov 25, 2019

Closes #284

This PR adds the option --warn-error to turn warnings into errors.
It is implemented using a global flag and failing after warnings are printed.

This is the easier implementation I found and it has some problems:

  • Very few warnings are accumulated before shed_warnings is called and the error is raised.
  • It's a global variable that is very deep in the dependency chain

I also started looking into other ways that require refactoring:

  • Passing the warning accumulator everywhere
    It's how the parser works but makes the code very verbose and introduce a lot of diffs. (~300 adds)
  • Change Error.catch to also "catch" warnings
    This is also a lot of changes and requires to change the API of Error to avoid bad uses, which requires even more refactoring.
  • Monad style would drastically change the whole codebase

What do you think?

@jonludlam
Copy link
Member

Looks like the failures are due to the expect tests expecting exact line numbers in the backtraces.

@Julow
Copy link
Collaborator Author

Julow commented Nov 28, 2019

This error message is very bad anyway, I wanted feedback before changing it.
Failure is raised in odoc/* when handling errors from Odoc_loader.read_* and are not catch.
I changed the code to properly handle that error but the output is still an unhandled exception.

@aantron
Copy link
Contributor

aantron commented Nov 29, 2019

This looks fine. We can refactor it later, either passing a warning accumulator, or converting to monadic style.

How are you invoking odoc with --warn-error?

The test should be fixed to pass, which I guess will happen when you fix up the error message :)

For Compile, Html_fragment and Odoc_html
@Julow
Copy link
Collaborator Author

Julow commented Nov 29, 2019

The option is added to odoc compile, odoc html and odoc html-fragment. Do other commands need it ?
I commited a small refactor that propagate the errors up to the main and print/exit there. This is only for the 3 subcommands, so it's not very consistent. I can work on doing that for all the subcommands in an other PR if you think it's a good approach ?

@aantron
Copy link
Contributor

aantron commented Nov 29, 2019

The option is added to odoc compile, odoc html and odoc html-fragment. Do other commands need it ?

What I meant is, how are you driving odoc? I am just curious for comparison. AFAIK when driving odoc through Dune, users still won't have easy access to the option.

I commited a small refactor that propagate the errors up to the main and print/exit there. This is only for the 3 subcommands, so it's not very consistent. I can work on doing that for all the subcommands in an other PR if you think it's a good approach ?

The refactor looks okay at first glance, it is at least more consistent than what we had before :) I would accept a second PR for this. However, a lot of this code is probably in need of even more fundamental refactoring with respect to error propagation and reporting.

@Julow
Copy link
Collaborator Author

Julow commented Dec 2, 2019

What I meant is, how are you driving odoc? I am just curious for comparison. AFAIK when driving odoc through Dune, users still won't have easy access to the option.

My first thought was that is Dune's job. Just like libraries, dune build @doc is for dev builds and dune build -p my_package @doc for release builds. Also, the (documentation ..) stanza could allow to enable or disable explicitly this flag (or allow to pass flags directly).
I don't known about other tools calling Odoc. Do you think a different API is needed ? (eg. an env variable)

The refactor looks okay at first glance, it is at least more consistent than what we had before :) I would accept a second PR for this. However, a lot of this code is probably in need of even more fundamental refactoring with respect to error propagation and reporting.

I'd like to split this in an other PR and go a little bit further to make things a little cleaner.

@aantron
Copy link
Contributor

aantron commented Dec 2, 2019

Ok, that all sounds good.

@Julow Julow mentioned this pull request Dec 3, 2019
Copy link
Contributor

@aantron aantron left a comment

Choose a reason for hiding this comment

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

Is this PR ready for merge? It looks good to me.

@aantron aantron merged commit 9e37f1a into ocaml:master Dec 4, 2019
@Julow
Copy link
Collaborator Author

Julow commented Dec 4, 2019

Sorry for the delay and thanks for merging :)
Do you think I should open an issue on the limitations of this PR ?
Only a few warnings are printed before the error is raised terminating the program instead of collecting all the warnings.

@aantron
Copy link
Contributor

aantron commented Dec 4, 2019

Do you think I should open an issue on the limitations of this PR ?
Only a few warnings are printed before the error is raised terminating the program instead of collecting all the warnings.

Yes, please :)

jonludlam added a commit to jonludlam/opam-repository that referenced this pull request Feb 7, 2020
CHANGES:

Additions

- Add option to turn warnings into errors (ocaml/odoc#398, Jules Aguillon)

Bugs fixed

- Emit quote before identifier in alias type expr (Fixes ocaml/odoc#391, Anton Bachin)
- Handle generalized open statements introduced in 4.08 (ocaml/odoc#393, Jon Ludlam)
- Refactor error reporting to avoid exiting the program in library code
  (ocaml/odoc#400, Jules Aguillon)
- Build on OCaml 4.10 (ocaml/odoc#408, Jon Ludlam)
mgree pushed a commit to mgree/opam-repository that referenced this pull request Feb 19, 2020
CHANGES:

Additions

- Add option to turn warnings into errors (ocaml/odoc#398, Jules Aguillon)

Bugs fixed

- Emit quote before identifier in alias type expr (Fixes ocaml/odoc#391, Anton Bachin)
- Handle generalized open statements introduced in 4.08 (ocaml/odoc#393, Jon Ludlam)
- Refactor error reporting to avoid exiting the program in library code
  (ocaml/odoc#400, Jules Aguillon)
- Build on OCaml 4.10 (ocaml/odoc#408, Jon Ludlam)
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.

Add option to fail on warnings
3 participants