openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.15k stars 322 forks source link

Recipe validation error should contain recipe #3587

Closed Bananeweizen closed 9 months ago

Bananeweizen commented 1 year ago

What problem are you trying to solve?

I'd like to understand which recipe actually caused which validation error. Sample output from the Maven plugin:

[INFO] Validating active recipes...
[ERROR] Recipe validation error in runtime: is required
[ERROR] Recipe validation error in runtime: is required
[ERROR] Recipe validation error in runtime: is required
[ERROR] Recipe validation error in runtime: is required
[ERROR] Recipe validation error in runtime: is required
[ERROR] Recipe validation error in org.openrewrite.java.security.OwaspTopTen.recipeList[6] (in jar:file:/C:/Users/Admin/.m2/repository/org/openrewrite/recipe/rewrite-java-security/2.0.4/rewrite-java-security-2.0.4.jar!/META-INF/rewrite/owasp.yml): recipe 'org.openrewrite.java.security.OwaspA010' does not exist.
[ERROR] Recipe validation error in scope: is required
[ERROR] Recipe validation error in builderType: is required
[ERROR] Recipe validation error in builderType: must not be blank
[ERROR] Recipe validation error in cveList: is required
[ERROR] Recipe validation error in runtime: is required
[ERROR] Recipe validation error in runtime: is required
[ERROR] Recipe validation error in runtime: is required
[ERROR] Recipe validation error in runtime: is required
[ERROR] Recipe validation error in runtime: is required

The problem stems from the validation just collecting a list of failure messages, without any relation to the recipe(s): https://github.com/openrewrite/rewrite/blob/7ef3ffcb9d659eb57437ad47dce3ed474b719117/rewrite-core/src/main/java/org/openrewrite/Recipe.java#L318

Describe the solution you'd like

make validateAll(...) return a Map<Recipe, Collection<Validated>> instead, such that every build tool can show recipe and failure.

SumanohariR commented 1 year ago

Hello, I hope you're all doing well! I'm a newcomer, and I think I have the required abilities to solve this issue. Could you please assign it to me? It would be a pleasure to contribute to your project!