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

[core] Better error reporting for the ruleset parser #3922

Merged
merged 22 commits into from
Jul 14, 2022

Conversation

oowekyala
Copy link
Member

@oowekyala oowekyala commented Apr 15, 2022

Describe the PR

Use the library I wrote to display nice error messages when parsing the ruleset XML. This also uniformizes the error handling, which previously was a mix of IllegalArgumentExceptions and logger calls.

Sample output:

[main] ERROR net.sourceforge.pmd.PMD - Error at sandbox/broken-rset.xml:75:5
 73|     <!--    </rule>-->
 74| 
 75|     <rule ref="category/java/codestyle.xml/UxxxnnecessaryImport" />
         ^^^^^ Unable to find referenced rule UxxxnnecessaryImport; perhaps the rule name is misspelled?

 76| 
 77|     <rule ref="category/java/codestyle.xml/UnnecessaryImport">
[main] ERROR net.sourceforge.pmd.PMD - Error at sandbox/broken-rset.xml:78:12
 76| 
 77|     <rule ref="category/java/codestyle.xml/UnnecessaryImport">
 78|            <priority>0</priority>
                ^^^^^^^^^ Not a valid priority: '0', expected a number in [1,5]

 79|     </rule>
 80| 
[main] ERROR net.sourceforge.pmd.PMD - Cannot load ruleset sandbox/broken-rset.xml: 2 XML validation errors occurred

Note that as per #3816 we will stop using a Logger to report these errors, so that the [main] ERROR net.sourceforge.pmd.PMD headers will disappear

Previously (notice the second error is not reported):

[main] ERROR net.sourceforge.pmd.PMD - Cannot load ruleset sandbox/broken-rset.xml: Unable to find referenced rule UxxxnnecessaryImport; perhaps the rule name is misspelled?
[main] WARN net.sourceforge.pmd.PMD - No rules found. Maybe you misspelled a rule name? (sandbox/broken-rset.xml)

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)

@oowekyala oowekyala added this to the 6.45.0 milestone Apr 15, 2022
@oowekyala oowekyala modified the milestones: 6.45.0, 7.0.0 Apr 16, 2022
@oowekyala oowekyala added this to In progress in PMD 7 via automation Apr 16, 2022
@oowekyala oowekyala marked this pull request as ready for review June 25, 2022 17:29
@pmd-test
Copy link

pmd-test commented Jun 25, 2022

2 Messages
📖 Compared to pmd/7.0.x:
This changeset changes 22 violations,
introduces 27 new violations, 0 new errors and 0 new configuration errors,
removes 22 violations, 0 errors and 0 configuration errors.
Full report
📖 Compared to master:
This changeset changes 57093 violations,
introduces 34427 new violations, 2 new errors and 0 new configuration errors,
removes 138135 violations, 25 errors and 6 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 21 violations,
introduces 21 new violations, 0 new errors and 0 new configuration errors,
removes 21 violations, 0 errors and 0 configuration errors.
[Full report](<html>

<title>504 Gateway Time-out</title>

504 Gateway Time-out


nginx

</html>/diff1/index.html)

Compared to master:
This changeset changes 57096 violations,
introduces 34419 new violations, 2 new errors and 0 new configuration errors,
removes 138132 violations, 25 errors and 6 configuration errors.
[Full report](<html>

<title>504 Gateway Time-out</title>

504 Gateway Time-out


nginx

</html>/diff2/index.html)

Compared to pmd/7.0.x:
This changeset changes 23 violations,
introduces 20 new violations, 0 new errors and 0 new configuration errors,
removes 27 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 57096 violations,
introduces 34417 new violations, 2 new errors and 0 new configuration errors,
removes 138132 violations, 25 errors and 6 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 32 violations,
introduces 18 new violations, 0 new errors and 0 new configuration errors,
removes 16 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 57095 violations,
introduces 34427 new violations, 2 new errors and 0 new configuration errors,
removes 138133 violations, 25 errors and 6 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 30 violations,
introduces 19 new violations, 0 new errors and 0 new configuration errors,
removes 20 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 57095 violations,
introduces 34424 new violations, 2 new errors and 0 new configuration errors,
removes 138133 violations, 25 errors and 6 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 19 violations,
introduces 15 new violations, 0 new errors and 0 new configuration errors,
removes 13 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 57095 violations,
introduces 34428 new violations, 2 new errors and 0 new configuration errors,
removes 138133 violations, 25 errors and 6 configuration errors.
Full report

Generated by 🚫 Danger

@adangel adangel self-assigned this Jul 14, 2022
Copy link
Member

@adangel adangel left a comment

Choose a reason for hiding this comment

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

Many Thanks! 🎉 This will provide much more useful error messages than ever!

I'll update your library to 3.1 and merge this.

pmd-core/pom.xml Show resolved Hide resolved
@@ -1022,6 +1022,19 @@
</pluginRepositories>

<profiles>
<profile>
<!-- Adds an SLF4J implementation, useful when developing within an IDE -->
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can add this as test dependency in general?
Hm... for core, we have this already.
In java, it is missing.
Or do you need it, when you run CLI from within an IDE?

I'll keep it in, but would be interested in how you use it...

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it was to run tests like CliTest (in module pmd-java). Intellij would run them but print a warning that there is no logger implementation, and hid the messages. I'm not sure a profile is the best way, maybe just having the test dependency as you suggest would be better...

Copy link
Member Author

Choose a reason for hiding this comment

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

@adangel I remember now where I needed this. I have a bunch of run configurations for Intellij which run the main class PMD with different arguments. Most of them use the classpath of pmd-java, so that you can launch them quicker (Intellij only needs to build pmd-java and its dependencies, not all modules). But Intellij doesn't use test dependencies when a run configuration depends on a module, so without the profile there would be no slf4j impl in this setup.

adangel added a commit that referenced this pull request Jul 14, 2022
[core] Better error reporting for the ruleset parser #3922
@adangel adangel merged commit 24e159a into pmd:pmd/7.0.x Jul 14, 2022
PMD 7 automation moved this from In progress to Done Jul 14, 2022
@oowekyala oowekyala deleted the xml-messages-in-ruleset-parser branch July 15, 2022 09:19
@oowekyala
Copy link
Member Author

Thanks for merging!

oowekyala added a commit to adangel/pmd that referenced this pull request Jul 16, 2022
They were merged on separate branches
@adangel adangel added the in:ruleset-xml About the ruleset schema/parser label Jan 13, 2023
@adangel adangel mentioned this pull request Jan 23, 2023
55 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in:ruleset-xml About the ruleset schema/parser
Projects
No open projects
PMD 7
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants