Skip to content

Commit

Permalink
Merge pull request #40947 from aloubyansky/resolver-error-formatting
Browse files Browse the repository at this point in the history
Better error reporting and formattering in WorkspaceLoader and incubating dependency resolver
  • Loading branch information
aloubyansky authored Jun 4, 2024
2 parents 3312986 + 1f791ea commit 5f37921
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,17 @@ private void assertNoErrors() {
log.error(prefix, error);
sb.append(System.lineSeparator()).append(prefix).append(" ").append(error.getLocalizedMessage());
for (var e : error.getStackTrace()) {
sb.append(System.lineSeparator()).append(e);
sb.append(System.lineSeparator());
for (int j = 0; j < prefix.length(); ++j) {
sb.append(" ");
}
sb.append("at ").append(e);
if (e.getClassName().contains("io.quarkus")) {
sb.append(System.lineSeparator());
for (int j = 0; j < prefix.length(); ++j) {
sb.append(" ");
}
sb.append("...");
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ LocalProject load() throws BootstrapMavenException {
};
}

final ConcurrentLinkedDeque<Exception> errors = new ConcurrentLinkedDeque<>();
while (!moduleQueue.isEmpty()) {
ConcurrentLinkedDeque<RawModule> newModules = new ConcurrentLinkedDeque<>();
while (!moduleQueue.isEmpty()) {
Expand All @@ -169,12 +170,15 @@ LocalProject load() throws BootstrapMavenException {
CompletableFuture.runAsync(() -> {
try {
loadModule(module, newModules);
} catch (Exception e) {
errors.add(e);
} finally {
phaser.arriveAndDeregister();
}
});
}
phaser.arriveAndAwaitAdvance();
assertNoErrors(errors);
}
for (var newModule : newModules) {
newModule.process(processor);
Expand Down Expand Up @@ -280,6 +284,35 @@ public List<String> findVersions(Artifact artifact) {
return model == null ? List.of() : List.of(ModelUtils.getVersion(model));
}

private void assertNoErrors(Collection<Exception> errors) throws BootstrapMavenException {
if (!errors.isEmpty()) {
var sb = new StringBuilder("The following errors were encountered while loading the workspace:");
log.error(sb);
var i = 1;
for (var error : errors) {
var prefix = i++ + ")";
log.error(prefix, error);
sb.append(System.lineSeparator()).append(prefix).append(" ").append(error.getLocalizedMessage());
for (var e : error.getStackTrace()) {
sb.append(System.lineSeparator());
for (int j = 0; j < prefix.length(); ++j) {
sb.append(" ");
}
sb.append("at ").append(e);
if (e.getClassName().contains("io.quarkus")) {
sb.append(System.lineSeparator());
for (int j = 0; j < prefix.length(); ++j) {
sb.append(" ");
}
sb.append("...");
break;
}
}
}
throw new BootstrapMavenException(sb.toString());
}
}

private static Model readModel(Path pom) {
try {
final Model model = ModelUtils.readModel(pom);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>

<artifactId>root-module1</artifactId>

<build>
<resources>
<resource>
Expand Down

0 comments on commit 5f37921

Please sign in to comment.