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); + } + } }