Skip to content

Commit

Permalink
channel early error through normal error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
teshull authored and c-refice committed May 28, 2024
1 parent cbbdc31 commit 9173929
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -705,23 +705,21 @@ public void printEpilog(Optional<String> optionalImageName, Optional<NativeImage
executor.shutdown();

boolean singletonSupportAvailable = ImageSingletonsSupport.isInstalled() && ImageSingletons.contains(BuildArtifacts.class) && ImageSingletons.contains(TimerCollection.class);
if (!singletonSupportAvailable) {
l().a("Failed early during image build process").println();
printErrorMessage(optionalUnhandledThrowable, parsedHostedOptions, true);
return;
}

if (optionalUnhandledThrowable.isPresent()) {
Path errorReportPath = NativeImageOptions.getErrorFilePath(parsedHostedOptions);
Optional<FeatureHandler> featureHandler = optionalGenerator.map(nativeImageGenerator -> nativeImageGenerator.featureHandler);
ReportUtils.report("GraalVM Native Image Error Report", errorReportPath,
p -> VMErrorReporter.generateErrorReport(p, buildOutputLog, classLoader, featureHandler, optionalUnhandledThrowable.get()),
false);
if (!singletonSupportAvailable) {
printErrorMessage(optionalUnhandledThrowable, parsedHostedOptions);
return;
}
BuildArtifacts.singleton().add(ArtifactType.BUILD_INFO, errorReportPath);
}

if (optionalImageName.isEmpty() || optionalGenerator.isEmpty()) {
printErrorMessage(optionalUnhandledThrowable, parsedHostedOptions, false);
if (!singletonSupportAvailable || optionalImageName.isEmpty() || optionalGenerator.isEmpty()) {
printErrorMessage(optionalUnhandledThrowable, parsedHostedOptions);
return;
}
String imageName = optionalImageName.get();
Expand All @@ -747,17 +745,17 @@ public void printEpilog(Optional<String> optionalImageName, Optional<NativeImage
l().a(wasSuccessfulBuild ? "Finished" : "Failed").a(" generating '").bold().a(imageName).reset().a("' ")
.a(wasSuccessfulBuild ? "in" : "after").a(" ").a(timeStats).a(".").println();

printErrorMessage(optionalUnhandledThrowable, parsedHostedOptions, false);
printErrorMessage(optionalUnhandledThrowable, parsedHostedOptions);
}

private void printErrorMessage(Optional<Throwable> optionalUnhandledThrowable, OptionValues parsedHostedOptions, boolean forceStackTrace) {
private void printErrorMessage(Optional<Throwable> optionalUnhandledThrowable, OptionValues parsedHostedOptions) {
if (optionalUnhandledThrowable.isEmpty()) {
return;
}
Throwable unhandledThrowable = optionalUnhandledThrowable.get();
l().println();
l().redBold().a("The build process encountered an unexpected error:").reset().println();
if (forceStackTrace || NativeImageOptions.ReportExceptionStackTraces.getValue(parsedHostedOptions)) {
if (NativeImageOptions.ReportExceptionStackTraces.getValue(parsedHostedOptions)) {
l().dim().println();
unhandledThrowable.printStackTrace(builderIO.getOut());
l().reset().println();
Expand Down

0 comments on commit 9173929

Please sign in to comment.