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

[MNG-7351] clarify differences between MojoFailureException and MojoExecutionException in javadoc #632

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kwin
Copy link
Member

@kwin kwin commented Dec 6, 2021

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [MNG-XXX] - Fixes bug in ApproximateQuantiles,
    where you replace MNG-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the Core IT successfully.

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@kwin kwin force-pushed the MNG-7351-improve-javadoc-MojoFailureException-and-MojoExecutionException branch from 1c69460 to 941f82e Compare December 6, 2021 15:02
@gnodet
Copy link
Contributor

gnodet commented Dec 8, 2021

@kwin I think it would be interesting to add pointers to the code where those exceptions are actually handled ? I must admit I tried to find them but I haven't been able to find them in a timely manner. For example there's no BUILD ERROR string in the whole codebase...

@kwin
Copy link
Member Author

kwin commented Dec 8, 2021

@gnodet Indeed I couldn't find anything either yet. TBH I have just taken the information from https://books.sonatype.com/mvnref-book/reference/writing-plugins-sect-custom-plugin.html#writing-plugins-sect-failure which I consider a pretty reliable source. But maybe the different handling of those exceptions has vanished over time. Will do some more tests....

@kwin
Copy link
Member Author

kwin commented Dec 8, 2021

I tried it out with a dummy mojo and both exceptions behave exactly the same, i.e. both emit "BUILD FAILURE". I couldn't influence the build outcome with any of the --fail-xxx options nor continue the build after the exception happened. I had a quick look in the commit logs and found (06dc81b#diff-976d393f31905911c189adc496696a5047b0aae4526ba1c5d13bf7502ce2cbca) which once treated MojoExecutionException separately, but that class has been removed in ae1501b (with Maven 3), so most probably having two different exception classes is no longer useful in Maven 3...

@kwin kwin marked this pull request as draft December 8, 2021 09:02
@kwin
Copy link
Member Author

kwin commented Dec 8, 2021

Given that, I would recommend to either reestablish the different semantics or deprecate one exception class of the two. In any case right now it is highly confusing why there are two different exception classes and when to use which in mojos.

@kwin
Copy link
Member Author

kwin commented Dec 8, 2021

Dug a bit deeper and found

else if ( exception instanceof MojoFailureException )
{
MojoFailureException e = (MojoFailureException) exception;
logFailure( response, e, e.getLongMessage() );
}
else if ( exception instanceof MojoExecutionException )
{
// TODO: replace by above
if ( exception.getCause() == null )
{
MojoExecutionException e = (MojoExecutionException) exception;
logFailure( response, e, e.getLongMessage() );
}
else
{
// TODO: throw exceptions like this, so "failures" are just that
logError( response );
}
}
for the different handling.

@gnodet
Copy link
Contributor

gnodet commented Dec 8, 2021

Dug a bit deeper and found

else if ( exception instanceof MojoFailureException )
{
MojoFailureException e = (MojoFailureException) exception;
logFailure( response, e, e.getLongMessage() );
}
else if ( exception instanceof MojoExecutionException )
{
// TODO: replace by above
if ( exception.getCause() == null )
{
MojoExecutionException e = (MojoExecutionException) exception;
logFailure( response, e, e.getLongMessage() );
}
else
{
// TODO: throw exceptions like this, so "failures" are just that
logError( response );
}
}

for the different handling.

Now, the exceptions are handled in BuilderCommon and no case is done whether the exception is a MojoFailureException or MojoExecutionException which is coherent with your experiments. If we confirm this, I'd change the javadoc and eventually deprecate one of the exceptions.

@rmannibucau
Copy link
Contributor

My understanding was that MojoExecutionException is a wrapper around another exception as primary usage whereas MojoFailureException is a root exception by itself (and previous handling tends to confirm it).

Overall the need of these exception is that mojo don't throw an Exception/Throwable but there is no technical reason - in particular now, so ultimately we can just deprecate both and change mojo contract for 4.0, no?

@kwin
Copy link
Member Author

kwin commented Dec 8, 2021

Overall the need of these exception is that mojo don't throw an Exception/Throwable but there is no technical reason

I think the reason is to throw an exception which would allow Maven to continue (by using --fail-never or --fail-at-end, https://maven.apache.org/ref/3.8.4/maven-embedder/cli.html). Using an unchecked exception will IMHO always lead to an immediate failure and broken Maven build.

@rmannibucau
Copy link
Contributor

@kwin not sure, --fail-never will ignore the exception and --fail-at-end will stack it to fail after other modules build so MojoXXXExceptons never bring anything in this logic (as proven by BuilderCommon impl) so think it is fine to remove this constraint. There is no real recovery exception in maven - and don't think we need one.

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

Successfully merging this pull request may close these issues.

3 participants