Skip to content

Commit

Permalink
Merge pull request #19294 from gsmet/avoid-exception-wrapping-2
Browse files Browse the repository at this point in the history
Avoid exception wrapping when native image build error
  • Loading branch information
gsmet authored Dec 18, 2021
2 parents 58ec64c + 3f96b18 commit e866c8e
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -851,4 +853,11 @@ private void handleAdditionalProperties(List<String> command) {
}
}
}

private static class ImageGenerationFailureException extends RuntimeException {

private ImageGenerationFailureException(String message) {
super(message);
}
}
}

0 comments on commit e866c8e

Please sign in to comment.