From 0a1cb72c3ce258e4179a9751476765cfa64b4010 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 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 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 2210a067887cb..80a8bd6e7431a 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 @@ -231,6 +231,8 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa new NativeImageBuildItem.GraalVMVersion(graalVMVersion.fullVersion, graalVMVersion.major, graalVMVersion.minor, graalVMVersion.distribution.name())); + } catch (ImageGenerationFailureException e) { + throw e; } catch (Exception e) { throw new RuntimeException("Failed to build native image", e); } finally { @@ -362,19 +364,19 @@ private static void copySourcesToSourceCache(OutputTargetBuildItem outputTargetB } } - private RuntimeException imageGenerationFailed(int exitValue, List command) { + private ImageGenerationFailureException imageGenerationFailed(int exitValue, List command) { if (exitValue == OOM_ERROR_VALUE) { if (command.contains("docker") && !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); } } @@ -743,4 +745,11 @@ private void handleAdditionalProperties(NativeConfig nativeConfig, List } } } + + private static class ImageGenerationFailureException extends RuntimeException { + + private ImageGenerationFailureException(String message) { + super(message); + } + } }