Skip to content

[cli] Add exit code for processing errors#4991

Merged
adangel merged 17 commits into
pmd:masterfrom
adangel:cli-exit-codes-processing-errors
Jun 27, 2024
Merged

[cli] Add exit code for processing errors#4991
adangel merged 17 commits into
pmd:masterfrom
adangel:cli-exit-codes-processing-errors

Conversation

@adangel

@adangel adangel commented May 3, 2024

Copy link
Copy Markdown
Member

Describe the PR

This adds a new exit code 5 when processing errors occurred (both in PMD and CPD).
This helps in avoiding that such errors are unnoticed.
I think, it's better to fail in such cases than to ignore processing errors.

Not sure, whether an extra exit code 5 really beneficial or needed or we should reuse exit code 4 (which is violations only). The problem I see with exit code 5, you only know that one or more processing errors occurred, but you don't know whether there were any violations. We could of course add another exit code 6 (Only processing errors but no violations). I don't know, whether this is really needed.

The main goal I had is: I want to fail the build in case of processing errors. The result of a failing build is usually the same (regardless of the failure cause): I need to look at the build, logs, changes, to figure out the problem and solve it. The exit code gives only a little bit more information.

Interestingly, this feature was already present in the ant task. It is requested for gradle (gradle/gradle#28672). And the feature is also available in maven-pmd-plugin, but disabled by default. There is a request to fail the build by default in the presence of processing errors (https://issues.apache.org/jira/browse/MPMD-383).

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

@adangel adangel added the in:cli Affects the PMD Command Line Interface label May 3, 2024
@ghost

ghost commented May 3, 2024

Copy link
Copy Markdown
1 Message
📖 Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Download full report as build artifact
Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Download full report as build artifact
Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Download full report as build artifact
Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Download full report as build artifact
Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Download full report as build artifact

Generated by 🚫 Danger

@oowekyala oowekyala self-requested a review May 3, 2024 20:43

@oowekyala oowekyala left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR

I think we should also consider CPD's --skip-lexical-errors with this PR. It seems to me we should deprecate --skip-lexical-errors in favor of the new flag.

Currently CPD lexes all files and once it is done, if there was an error it recovered from, it just gives up if --skip-lexical-errors is not set. I think this is not good behavior, as we already recovered from all errors at this point. In this case, I think we should continue execution and just make sure the exit code reflects whether there were errors or not (also respecting the flags --fail-on-violation and --fail-on-error). This would align PMD and CPD closer.

Another thing is I think we should stop using the phrase "processing error" in our doc and especially in the new switch --fail-on-processing-error. What a "processing error" is is vague and although we use it sometimes in our doc we don't explain it anywhere. It is likely our users have no idea how a "processing error" is different from an "error".

FWIW what we call today a "processing error" is just an error we recovered from gracefully, and which didn't prevent us from outputting a report. There is no difference in nature from other errors, just in how we handled it. That's why I think this phrase it weird and cryptic. There are two kinds of errors in PMD/CPD:

  • Errors which were unexpected and we did not recover from. These cause exit code 1, and when they happen, then the report is either non-existent (we failed before reporting) or broken (we failed during reporting).
  • Errors from which we recovered gracefully ("processing errors"). They did not prevent the creation of a valid report, and these errors are actually part of the rendered report. Under your proposal these would cause exit code 5.

I think it would be better if we dropped the phrase "processing error" and just referred to these as "errors", or "recovered errors" if that's not clear from context.

So I would like to have the new flag named --[no-]fail-on-error without the processing.

Comment thread docs/pages/pmd/userdocs/cli_reference.md Outdated
Comment thread docs/pages/pmd/userdocs/cli_reference.md Outdated
@adangel

This comment was marked as resolved.

@adangel adangel marked this pull request as draft May 7, 2024 17:47
@adangel adangel marked this pull request as ready for review May 17, 2024 14:47
Comment thread docs/pages/pmd/userdocs/tools/ant.md Outdated
Comment thread pmd-core/src/main/java/net/sourceforge/pmd/AbstractConfiguration.java Outdated
Comment thread pmd-core/src/main/java/net/sourceforge/pmd/AbstractConfiguration.java Outdated
Comment thread docs/pages/release_notes.md
- release notes: API Changes
- fix javadoc since tags
- improve messages in ant task for deprecated skipLexicalErrors
@adangel adangel added this to the 7.2.0 milestone May 20, 2024
@adangel adangel modified the milestones: 7.2.0, 7.3.0 May 31, 2024

@adangel adangel left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated to be included in 7.3.0

Comment thread docs/pages/pmd/userdocs/cli_reference.md Outdated
Comment thread docs/pages/pmd/userdocs/cli_reference.md Outdated
Comment thread docs/pages/pmd/userdocs/cli_reference.md Outdated
Comment thread docs/pages/pmd/userdocs/cpd/cpd.md Outdated
Comment thread docs/pages/pmd/userdocs/cpd/cpd.md Outdated
Comment thread pmd-ant/src/main/java/net/sourceforge/pmd/ant/CPDTask.java Outdated
Comment thread pmd-core/src/main/java/net/sourceforge/pmd/AbstractConfiguration.java Outdated
Comment thread pmd-core/src/main/java/net/sourceforge/pmd/AbstractConfiguration.java Outdated
Comment thread pmd-core/src/main/java/net/sourceforge/pmd/AbstractConfiguration.java Outdated
Comment thread pmd-core/src/main/java/net/sourceforge/pmd/AbstractConfiguration.java Outdated
@adangel adangel merged commit e93ca46 into pmd:master Jun 27, 2024
@adangel adangel deleted the cli-exit-codes-processing-errors branch June 27, 2024 13:17
oowekyala added a commit to oowekyala/pmd that referenced this pull request Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in:cli Affects the PMD Command Line Interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cli] Consider processing errors in exit status

2 participants