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
[cli] Consider processing errors in exit status #2827
Comments
Ok, let's try to describe, what the behaviour should be, then compare it to the current behavior. I assume, when you say "PMDException" you actually mean "processing error", right? According to the documentation on https://pmd.github.io/latest/pmd_userdocs_cli_reference.html, here are the combinations:
Explanations / Definitions:
It boils down to the question: How should be handle processing errors? If we consider processing errors as potential false negatives, then we should probably return "4". 4 basically means: PMD executed, but something is wrong with a rule or part of the code couldn't be parsed and has been skipped. --> processing errors == violations Or we could return "1". But "1" usually means, that PMD complete crashed and the analysis didn't run at all, so there are no results, not even partial results, that can be used. If we consider processing errors as exceptions, then we should return "1" regardless of "--failOnViolation". --> processing errors == exceptions I think currently processing errors are simply ignored completely. |
Technically, processing errors are potential false negatives i.e., they could be no violations (when the problem is resolved) or there could be violations. The exit code then could be PS: The tabling of the scenarios helped clarify the thinking. Thanks! |
Do you need a definitive answer to the above? I like the levels set out for exit codes in AmigaOS. A pity that completely reworking the exit codes to the levels set out is out of scope for this issue. |
I think the exit code for processing errors should be 0. Processing errors should be caused only by bugs in PMD, which can only be fixed after a release cycle at the earliest. Failing builds because of them would make a user's build fail without a possible fix on their part, apart from excluding the problematic files from analysis. Excluding the files would cause the same false-negatives as the processing errors, only they wouldn't be reported anywhere. So, I think processing errors should be ignored in the exit code, but logged on stderr / added to the report, ie, the current behavior is correct. |
Hmm... Makes sense... |
To close or not to close, @oowekyala ? |
Or do we need another flag, failOnProcessingErrors? What would that do? Then what does developing team do? |
Or revert back to the previous working PMD version... |
I am getting an exit code of 0 when encountering lexical errors. This is on PMD 7.0.0, Windows 2019 Server and PowerShell, e.g.
If I fix the above error THEN I get $LastExitCode of 4 so violations are found, The CI job is passing because of the 0 exit code, so we don't know that CPD is hitting errors and it's also not failing on violations. Not setting an exit code > 0 for lexical errors is causing violations to be missed. |
I did some testing - and both PMD and CPD behave the same in this regard: ParseExceptions or LexExceptions are logged but don't affect the exit code and therfore don't fail the build. This causes the issue, that such problems are not being noticed at all. I personally only check the logs, if the build failed. If the build was successful, then I assume, that everything worked as expected. I don't scroll up to look at potential log output.
I think, we should at least have an option to change the behavior to fail the build in such cases. Processing errors might be caused by a bug in PMD or might be caused by a bug in the application being analyzed (probably not a Java application, because we expect already compileable code for Java). See also the similar case for the maven-pmd-plugin here: https://issues.apache.org/jira/browse/MPMD-383 Reading this case, the default behavior should indeed be to fail the build if there are any processing errors or lex exceptions. |
Affects PMD Version:
6.28.0
Description:
Command line interface:
There are a couple of problems with the error code returned
currently. If failOnViolations is set and PMDException occurs, the error
code returned is 0, not 1. That's not expected.
If violations are present as well, the error code returned is 4, not 1.
Is this the norm or expected behaviour? It must be 1 while not failing to process violations.
When both occur, the more severe error code must be returned; in this case, 1.
Running PMD through:
CLI
PS: It's been a while since I've used the CLI. And it has slipped my mind as how to simulate a PMDException while executing it.
Referred from here.
The text was updated successfully, but these errors were encountered: