From 730fa6e6d2b86fa856c1afa06c9f7bb1171be9c7 Mon Sep 17 00:00:00 2001 From: ascopes <73482956+ascopes@users.noreply.github.com> Date: Sun, 4 Feb 2024 11:26:06 +0000 Subject: [PATCH] GH-86: Fix exception causes being omitted from Maven output --- .../ascopes/protobufmavenplugin/AbstractGenerateMojo.java | 4 +++- .../protobufmavenplugin/source/ProtoSourceResolver.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/ascopes/protobufmavenplugin/AbstractGenerateMojo.java b/src/main/java/io/github/ascopes/protobufmavenplugin/AbstractGenerateMojo.java index 9f41ba5f..14aeda30 100644 --- a/src/main/java/io/github/ascopes/protobufmavenplugin/AbstractGenerateMojo.java +++ b/src/main/java/io/github/ascopes/protobufmavenplugin/AbstractGenerateMojo.java @@ -264,7 +264,9 @@ public void execute() throws MojoExecutionException, MojoFailureException { throw new MojoExecutionException("Protoc invocation failed"); } } catch (ResolutionException | IOException ex) { - throw new MojoFailureException(this, ex.getMessage(), ex.getMessage()); + var mojoFailureException = new MojoFailureException(this, ex.getMessage(), ex.getMessage()); + mojoFailureException.initCause(ex); + throw mojoFailureException; } } diff --git a/src/main/java/io/github/ascopes/protobufmavenplugin/source/ProtoSourceResolver.java b/src/main/java/io/github/ascopes/protobufmavenplugin/source/ProtoSourceResolver.java index f14fbee4..0f019479 100644 --- a/src/main/java/io/github/ascopes/protobufmavenplugin/source/ProtoSourceResolver.java +++ b/src/main/java/io/github/ascopes/protobufmavenplugin/source/ProtoSourceResolver.java @@ -95,8 +95,10 @@ public Collection createProtoFileListings( } if (!exceptions.isEmpty()) { + var causeIterator = exceptions.iterator(); var ex = new IOException("Failed to create listings asynchronously"); - exceptions.forEach(ex::addSuppressed); + ex.initCause(causeIterator.next()); + causeIterator.forEachRemaining(ex::addSuppressed); throw ex; }