Skip to content

Commit

Permalink
Avoid exception wrapping when native image build error
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Aug 9, 2021
1 parent 086885f commit 0a1cb72
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -362,19 +364,19 @@ private static void copySourcesToSourceCache(OutputTargetBuildItem outputTargetB
}
}

private RuntimeException imageGenerationFailed(int exitValue, List<String> command) {
private ImageGenerationFailureException imageGenerationFailed(int exitValue, List<String> 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);
}
}

Expand Down Expand Up @@ -743,4 +745,11 @@ private void handleAdditionalProperties(NativeConfig nativeConfig, List<String>
}
}
}

private static class ImageGenerationFailureException extends RuntimeException {

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

0 comments on commit 0a1cb72

Please sign in to comment.