Skip to content

Commit

Permalink
Merge pull request #41215 from gsmet/more-info-error
Browse files Browse the repository at this point in the history
Quarkus Update - Provide more context when an error occurs
  • Loading branch information
gastaldi authored Jun 15, 2024
2 parents cd41895 + 5ce0688 commit c761702
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected void processProjectState(QuarkusProject quarkusProject) throws MojoExe
final QuarkusCommandOutcome result = invoker.execute();
if (!result.isSuccess()) {
throw new MojoExecutionException(
"Failed to apply the updates.");
"Failed to apply the updates: " + result.getMessage());
}
} catch (QuarkusUpdateExitErrorException e) {
throw new MojoExecutionException(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
package io.quarkus.devtools.commands.data;

import java.util.Objects;

public class QuarkusCommandOutcome extends ValueMap<QuarkusCommandOutcome> {

public static QuarkusCommandOutcome success() {
return new QuarkusCommandOutcome(true);
return new QuarkusCommandOutcome(true, null);
}

public static QuarkusCommandOutcome failure() {
return new QuarkusCommandOutcome(false);
public static QuarkusCommandOutcome failure(String message) {
Objects.requireNonNull(message, "Message may not be null in case of a failure");

return new QuarkusCommandOutcome(false, message);
}

private final boolean success;

public QuarkusCommandOutcome(boolean success) {
private final String message;

private QuarkusCommandOutcome(boolean success, String message) {
this.success = success;
this.message = message;
}

public boolean isSuccess() {
return success;
}

public String getMessage() {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
.forEach(a -> invocation.log()
.info(MessageIcons.NOOP_ICON + " Extension " + a.getGroupId() + ":" + a.getArtifactId()
+ " was already installed"));
return new QuarkusCommandOutcome(true).setValue(AddExtensions.OUTCOME_UPDATED, result.isSourceUpdated());
return QuarkusCommandOutcome.success().setValue(AddExtensions.OUTCOME_UPDATED, result.isSourceUpdated());
} else if (!extensionInstallPlan.getUnmatchedKeywords().isEmpty()) {
invocation.log()
.info(ERROR_ICON + " Nothing installed because keyword(s) '"
Expand All @@ -87,7 +87,7 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
throw new QuarkusCommandException("Failed to add extensions", e);
}

return new QuarkusCommandOutcome(false).setValue(AddExtensions.OUTCOME_UPDATED, false);
return QuarkusCommandOutcome.failure("see logs above for more details").setValue(AddExtensions.OUTCOME_UPDATED, false);
}

public ExtensionInstallPlan planInstallation(QuarkusCommandInvocation invocation, Collection<String> keywords)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws

final List<ArtifactCoords> extensionsToRemove = computeCoordsFromQuery(invocation, extensionsQuery);
if (extensionsToRemove == null) {
return new QuarkusCommandOutcome(false).setValue(RemoveExtensions.OUTCOME_UPDATED, false);
return QuarkusCommandOutcome.failure("no extensions to remove").setValue(RemoveExtensions.OUTCOME_UPDATED, false);
}
final ExtensionManager extensionManager = invocation.getValue(EXTENSION_MANAGER,
invocation.getQuarkusProject().getExtensionManager());
Expand All @@ -46,7 +46,7 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
.forEach(a -> invocation.log()
.info(MessageIcons.SUCCESS_ICON + " Extension " + a.getGroupId() + ":" + a.getArtifactId()
+ " has been uninstalled"));
return new QuarkusCommandOutcome(true).setValue(RemoveExtensions.OUTCOME_UPDATED, result.isSourceUpdated());
return QuarkusCommandOutcome.success().setValue(RemoveExtensions.OUTCOME_UPDATED, result.isSourceUpdated());
} catch (IOException e) {
throw new QuarkusCommandException("Failed to remove extensions", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
if (projectJavaVersion.isEmpty()) {
String instruction = invocation.getQuarkusProject().getBuildTool().isAnyGradle() ? "java>targetCompatibility"
: "maven.compiler.release property";
invocation.log().error(String.format("Project Java version not detected, set %s to fix the error.", instruction));
return QuarkusCommandOutcome.failure();
String error = String.format("Project Java version not detected, set %s in your build file to fix the error.",
instruction);

invocation.log().error(error);
return QuarkusCommandOutcome.failure(error);
} else {
invocation.log().info("Detected project Java version: %s", projectJavaVersion);
}
Expand All @@ -64,8 +67,10 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
invocation.getQuarkusProject().getExtensionsCatalog());
final ArtifactCoords projectQuarkusPlatformBom = getProjectQuarkusPlatformBOM(currentState);
if (projectQuarkusPlatformBom == null) {
invocation.log().error("The project does not import any Quarkus platform BOM");
return QuarkusCommandOutcome.failure();
String error = "The project does not import any Quarkus platform BOM";

invocation.log().error(error);
return QuarkusCommandOutcome.failure(error);
}
if (Objects.equals(projectQuarkusPlatformBom.getVersion(), targetPlatformVersion)) {
ProjectInfoCommandHandler.logState(currentState, perModule, true, invocation.getQuarkusProject().log());
Expand Down

0 comments on commit c761702

Please sign in to comment.