From 3f96b18e96022dd01af92f010ae01f31e98e783d Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Mon, 9 Aug 2021 10:27:31 +0200 Subject: [PATCH] Avoid exception wrapping when native image build error --- .../pkg/steps/NativeImageBuildStep.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java index 405ea9708c2b1..1b0e20db53db0 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java @@ -249,6 +249,8 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa graalVMVersion.version.toString(), graalVMVersion.javaFeatureVersion, graalVMVersion.distribution.name())); + } catch (ImageGenerationFailureException e) { + throw e; } catch (Exception e) { throw new RuntimeException("Failed to build native image", e); } finally { @@ -377,16 +379,16 @@ private static void copySourcesToSourceCache(OutputTargetBuildItem outputTargetB private RuntimeException imageGenerationFailed(int exitValue, boolean isContainerBuild) { if (exitValue == OOM_ERROR_VALUE) { if (isContainerBuild && !SystemUtils.IS_OS_LINUX) { - return new RuntimeException("Image generation failed. Exit code was " + exitValue + return new ImageGenerationFailureException("Image generation failed. Exit code was " + exitValue + " which indicates an out of memory error. The most likely cause is Docker not being given enough memory. Also consider increasing the Xmx value for native image generation by setting the \"" + QUARKUS_XMX_PROPERTY + "\" property"); } else { - return new RuntimeException("Image generation failed. Exit code was " + exitValue + return new ImageGenerationFailureException("Image generation failed. Exit code was " + exitValue + " which indicates an out of memory error. Consider increasing the Xmx value for native image generation by setting the \"" + QUARKUS_XMX_PROPERTY + "\" property"); } } else { - return new RuntimeException("Image generation failed. Exit code: " + exitValue); + return new ImageGenerationFailureException("Image generation failed. Exit code: " + exitValue); } } @@ -851,4 +853,11 @@ private void handleAdditionalProperties(List command) { } } } + + private static class ImageGenerationFailureException extends RuntimeException { + + private ImageGenerationFailureException(String message) { + super(message); + } + } }