-
Notifications
You must be signed in to change notification settings - Fork 330
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
Add --warnings-as-errors flag for non-zero exit code (Take 2) #1831
Add --warnings-as-errors flag for non-zero exit code (Take 2) #1831
Conversation
There's one thing that is left. The error message says the docs failed to build due to warnings, which is not true. The docs are generated: Also, what should the behavior be given mix docs uses generates epub and html, and one fail? Should none of them be created, or should they be judged independently. |
aff8cb8
to
a9f1060
Compare
We should definitely produce a build, because it allows users to introspect what was rendered even in the presence of warnings. |
Great. That simplifies things. There's is one issue though:
|
Producing at least 1 build is fine. I believe it would be easier to inspect the HTML version first anyways. You could also specify which format you wanted if you really needed the epub to inspect. |
We need to standardize this (ie. be consistent) since other formatters could be used. I am working on a fix that will generate everything, and error if it has to, at the end. |
lib/ex_doc/cli.ex
Outdated
cond do | ||
List.keymember?(opts, :version, 0) -> | ||
IO.puts("ExDoc v#{ExDoc.version()}") | ||
|
||
opts[:warnings_as_errors] == true and ExDoc.Utils.warned?() -> | ||
IO.puts( | ||
:stderr, | ||
"Doc generation failed due to warnings while using the --warnings-as-errors option" | ||
) | ||
|
||
exit({:shutdown, 1}) | ||
|
||
true -> | ||
generate(args, opts, generator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are checking for warnings without generating the docs. I believe this should rather be something like this:
if List.keymember?(opts, :version, 0) do
IO.puts("ExDoc v#{ExDoc.version()}")
else
generate(args, opts, generator)
if opts[:warnings_as_errors] == true and ExDoc.Utils.warned?() do
# ...
end
end
we need to improve cli_test.exs because it's not catching this bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have noticed this. I am sending a fix later today that addresses this and the issue regarding all docs being generated and failing after that.
test/ex_doc/cli_test.exs
Outdated
end | ||
|
||
test "exits with 1 when there is a warning" do | ||
ExDoc.Utils.set_warned() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as mentioned above there is a bug that this test is not catching. what about making it more realistic, have an actual .ex or .md file, and assert on the warning message?
86b29a6
to
f6e4c9e
Compare
@wojtekmach I have submitted new changes. Could you please have a look. |
There's a little issue with two lines of output generated during the test run, but we can talk about it later on before merging the PR. |
Is there any reason why this is being held back? |
Sorry, I was not aware this was ready to go. I would like to propose two changes:
|
Thank you! |
@josevalim which module are you referring to about introducing |
Any other than |
All the modules that need it, yes. The goal is to minimize the changes in the PR by not changing the return type of run. |
I get it now. It was about the return type. |
f6e4c9e
to
32a9cf1
Compare
Code have been changed to make the least changes. Regarding fixtures, I played around with them for an hour to no avail. If you have a clear idea of how to test this I can try. If not once there is a way of porting what's in a fixture to run without it I can take care of adapting the code. |
Could you rebase? I can help with testing this. |
32a9cf1
to
1529acb
Compare
1529acb
to
e25037f
Compare
Done. Thank you @wojtekmach |
message_formatted = IO.ANSI.format([:red, message, :reset]) | ||
|
||
IO.puts(:stderr, message_formatted) | ||
|
||
exit({:shutdown, 1}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
message_formatted = IO.ANSI.format([:red, message, :reset]) | |
IO.puts(:stderr, message_formatted) | |
exit({:shutdown, 1}) | |
message_formatted = IO.ANSI.format([:red, message, :reset]) | |
IO.puts(:stderr, message_formatted) | |
exit({:shutdown, 1}) |
message_formatted = IO.ANSI.format([:red, message, :reset]) | ||
|
||
IO.puts(:stderr, message_formatted) | ||
|
||
exit({:shutdown, 1}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
message_formatted = IO.ANSI.format([:red, message, :reset]) | |
IO.puts(:stderr, message_formatted) | |
exit({:shutdown, 1}) | |
message_formatted = IO.ANSI.format([:red, message, :reset]) | |
IO.puts(:stderr, message_formatted) | |
exit({:shutdown, 1}) |
Thank you, I'll do some minor updates on main. |
Nice! Looking forward to using this instead of the bash script hack that we have today. |
Awesome! |
Closes #1411 #1294
PR Originally published in #1412 #1564