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

adjusted MavenMojoProjectParser#logParseErrors to also log poms which… #833

Merged
merged 1 commit into from
Aug 9, 2024

Conversation

nmck257
Copy link
Contributor

@nmck257 nmck257 commented Aug 7, 2024

… were parsed correctly but encountered an error in resolution

What's changed?

see subject

What's your motivation?

Anything in particular you'd like reviewers to focus on?

In this implementation, these errors will get logged in the "Parsing source files..." step instead of the "Resolving poms..." step. Logging under the "resolving pom" step might be more intuitive, but this code change is more concise, and, gives an opportunity for the exclude-directory logic to run.

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

The message produced for ParseExceptionResult for a maven resolution issue is the entire source of the pom, with the relevant error markup comments. This is what will get logged here if --errors are enabled, and that's a bit bloated for log output. It might be nice to adjust that logic in rewrite-maven to instead produce an abbreviated summary of the problematic file's problems (like how git diff just skips to the changed lines, with a few lines of surrounding context)

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

… were parsed correctly but encountered an error in resolution
@nmck257
Copy link
Contributor Author

nmck257 commented Aug 7, 2024

side note, I'm thinking about a change like this in AbstractRewriteMojo, to elevate a little more error-reporting from recipes to the user if they add the --errors flag (without having to go all the way to -X debug output). haven't tested in detail yet

    protected ExecutionContext executionContext() {
        return new InMemoryExecutionContext(t -> {
            if (mavenSession.getRequest().isShowErrors()) {
                getLog().warn(t);
            } else {
                getLog().debug(t);
            }
        });
    }

@timtebeek timtebeek self-requested a review August 8, 2024 14:15
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Nice measured improvement here @nmck257 ! Appreciate how you connected the dots to spot that these were silently dropped; hope this avoids some confusion going forward.

@timtebeek timtebeek merged commit 11f7942 into main Aug 9, 2024
1 check passed
@timtebeek timtebeek deleted the feature/log-resolution-errors branch August 9, 2024 17:02
timtebeek added a commit to openrewrite/rewrite-gradle-plugin that referenced this pull request Aug 9, 2024
shanman190 pushed a commit to openrewrite/rewrite-gradle-plugin that referenced this pull request Aug 9, 2024
@nmck257
Copy link
Contributor Author

nmck257 commented Aug 9, 2024

thanks for mirroring over to gradle! @timtebeek

@timtebeek
Copy link
Contributor

I've taken a slightly different approach in this follow up, as we found that logging isn't working out great on a larger scale:
f592159...59404e5

Note the use of MojoFailureException, which still allows users to ignore partial failures if they really want to, and how we've pulled forward this feedback to where we parse the Maven pom files, as opposed to reporting these failures at the end.

@nmck257
Copy link
Contributor Author

nmck257 commented Sep 12, 2024

So the default behavior with this change will be to fail-fast the whole recipe execution (and print details) if we can't resolve pom(s)? I'm fine with that if we think that's the better choice.

Re ignoring partial failures -- does that mean that the user could instruct Maven to continue with other goals if the rewrite goal fails, or, something else?

@timtebeek
Copy link
Contributor

timtebeek commented Sep 12, 2024

I haven't tried it, but with --fail-never it looks like folks can ignore failures and continue with either the next task or next submodule; not sure which of those it'll end up being specifically, but figured that's at least a better option than the more definitive MojoExecutionException.

And yes indeed the thinking here is that a clear failure is better than skipping along and having changes not applied effectively, with a troublesome path to debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants