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

Detect duplicate artifacts and block deployment #32

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

@@ -106,6 +109,12 @@ private void doExecute() throws MojoFailureException, MojoExecutionException {
catch (MojoExecutionException e) {
throw e;
}
catch (dv ex) {
Optional<String> message = ex.b();
Copy link
Author

Choose a reason for hiding this comment

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

I have no idea why this needs to be obfuscated but an error message like this is very poor:

[ERROR] Failed to execute goal org.sonatype.plugins:nxrm3-maven-plugin:1.0.3:staging-deploy (default-cli) on project XYZ: Upload component was unsuccessful (400 response from server): Bad Request -> [Help 1]

Only executing Maven with --debug unveiled the real error:

[DEBUG] http-outgoing-3 << "[ {[\n]"
[DEBUG] http-outgoing-3 << "  "id" : "*",[\n]"
[DEBUG] http-outgoing-3 << "  "message" : "The assets 3 and 4 have identical coordinates"[\n]"
[DEBUG] http-outgoing-3 << "} ]"

@guw
Copy link
Author

guw commented Aug 17, 2022

Note, I think it would be better if the plug-in would not fail but just ignore duplicate artifacts, which can happen. In our case it worked fine with Nexus 2 for all those years. 🤷‍♂️

Comment on lines +118 to +119
if(message.isPresent())
throw new MojoFailureException(ex.getMessage() + ": " + message.get(), ex);

Choose a reason for hiding this comment

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

Please surround with curly braces

Comment on lines +127 to +153
private Optional<String> findJsonErrorMessage(Throwable e) {
if(e == null)
return Optional.empty();

if(e instanceof HttpResponseException) {
Method[] declaredMethods = e.getClass().getDeclaredMethods();
for (Method method : declaredMethods) {
if(method.getParameterCount() == 0 && isPublic(method.getModifiers()) && Optional.class.isAssignableFrom(method.getReturnType())) {
try {
Optional<?> result = (Optional<?>) method.invoke(e);
if(result.isPresent()) {
Object potentialMessage = result.get();
// filter out the raw json message
if(potentialMessage instanceof String && !((String)potentialMessage).contains("\"message\"")) {
return Optional.of((String)potentialMessage);
}
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e1) {
// ignore and continue
}
}
}
// nothing found
return Optional.empty();
}

return findJsonErrorMessage(e.getCause());
Copy link

@bobotimi bobotimi Aug 26, 2022

Choose a reason for hiding this comment

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

Please add tests to exercise the recursive flow in this new method.

Copy link
Author

Choose a reason for hiding this comment

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

@bobotimi I think it would be better if the team introduces a proper API to make the error response from Nexus part of the Nexus client API. For some reason the code is obfuscated, which doesn't make a lot of sense.

The reflection shouldn't be used as a long term solution.

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.

2 participants