-
Notifications
You must be signed in to change notification settings - Fork 172
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 --failure-level command line option to force non-zero exit code (fixes #1113) #1114
Conversation
…rom CLI if specified logging level is reached
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.
Thank you for your PR!
This looks great!
I added a few comments. What do you think about them?
public class SeverityConverter implements IStringConverter<Severity> { | ||
|
||
@Override | ||
public Severity convert(String argument) { return Severity.valueOf(argument.toUpperCase()); } |
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.
When I pass an invalid option like INFOX
I currently get a stacktrace back that does not show the currently supported options:
Exception in thread "main" java.lang.IllegalArgumentException: No enum constant org.asciidoctor.log.Severity.INFOX
at java.base/java.lang.Enum.valueOf(Enum.java:273)
at org.asciidoctor.log.Severity.valueOf(Severity.java:3)
at org.asciidoctor.jruby.cli.SeverityConverter.convert(SeverityConverter.java:10)
...
What do you think about changing it so that you'll get just a message with the invalid value and all supported values like:
Could not convert severity 'INFOX'. Supported values are [DEBUG, INFO, WARN, ERROR, FATAL, UNKNOWN]
Nitpick: Could you please add newlines after the opening brace?
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 agree - and it turns out JCommander has EnumConverter
class which gets us this nice error message for free.
@@ -507,8 +510,15 @@ private RubyClass getExtensionGroupClass() { | |||
|
|||
@Override | |||
public void log(LogRecord logRecord) { | |||
if (this.maxSeverity.compareTo(logRecord.getSeverity()) < 0) { | |||
this.maxSeverity = logRecord.getSeverity(); |
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.
JRubyAsciidoctor can be used in a multithreaded way when embedded into other environments like Spring Boot apps or sth similar.
In such scenarios it would be dangerous to rely on this property.
Could this be moved into a custom org.asciidoctor.log.LogHandler
that is only added by the AsciidoctorInvoker?
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.
Ok, moved this to MaxSeverityLogHandler under org.asciidoctor.jruby.cli package.
Thanks for the PR! 🎉 |
Kind of change
Description
The Ruby asciidoc CLI has option --failure-level which forces the CLI to exit with non-zero status code if the specified logging level (severity) is reached. See: asciidoctor/asciidoctor#2674, asciidoctor/asciidoctor#2003, asciidoctor/asciidoctor#854
This PR implements the same functionality for AsciidoctorJ, pretty much the same way as the Ruby code (keeps track of highest seen log message severity, and checks that the end).
The default value is the same as in Ruby - only "fatal" severity causes non-zero exit code - which probably won't break many things (but someone running AsciidoctorJ as part of a CI build would probably want to fail on "error" severity as well, maybe even "warn").
Issue
Fixes #1113