Skip to content

Commit

Permalink
[GR-52790] Print stack trace of UserException causes.
Browse files Browse the repository at this point in the history
PullRequest: graal/17882
  • Loading branch information
fniephaus committed Jun 19, 2024
2 parents 4de543b + a146c15 commit c62f53a
Showing 1 changed file with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import java.util.ServiceLoader;
import java.util.Set;
import java.util.TimerTask;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import org.graalvm.collections.Pair;
Expand Down Expand Up @@ -540,7 +539,7 @@ private int buildImage(ImageClassLoader classLoader) {
NativeImageGeneratorRunner.reportFatalError(e, "FallbackImageRequest while building fallback image.");
return ExitStatus.BUILDER_ERROR.getValue();
}
reportUserException(e, parsedHostedOptions, LogUtils::warning);
reportUserException(e, parsedHostedOptions);
return ExitStatus.FALLBACK_IMAGE.getValue();
} catch (ParsingError e) {
NativeImageGeneratorRunner.reportFatalError(e);
Expand All @@ -567,7 +566,7 @@ private int buildImage(ImageClassLoader classLoader) {
}

if (pee.getExceptions().size() > 1) {
System.err.println(pee.getExceptions().size() + " fatal errors detected:");
System.out.println(pee.getExceptions().size() + " fatal errors detected:");
}
for (Throwable exception : pee.getExceptions()) {
NativeImageGeneratorRunner.reportFatalError(exception);
Expand Down Expand Up @@ -653,8 +652,8 @@ public static void printCPUFeatures(Platform platform) {
* @param e error to be reported.
*/
protected static void reportFatalError(Throwable e) {
System.err.print("Fatal error: ");
e.printStackTrace();
System.out.print("Fatal error: ");
e.printStackTrace(System.out);
}

/**
Expand All @@ -664,8 +663,8 @@ protected static void reportFatalError(Throwable e) {
* @param msg message to report.
*/
protected static void reportFatalError(Throwable e, String msg) {
System.err.print("Fatal error: " + msg);
e.printStackTrace();
System.out.print("Fatal error: " + msg);
e.printStackTrace(System.out);
}

/**
Expand All @@ -674,7 +673,7 @@ protected static void reportFatalError(Throwable e, String msg) {
* @param msg error message that is printed.
*/
public static void reportUserError(String msg) {
System.err.println("Error: " + msg);
System.out.println("Error: " + msg);
}

/**
Expand All @@ -684,20 +683,28 @@ public static void reportUserError(String msg) {
* @param parsedHostedOptions
*/
public static void reportUserError(Throwable e, OptionValues parsedHostedOptions) {
reportUserException(e, parsedHostedOptions, NativeImageGeneratorRunner::reportUserError);
reportUserException(e, parsedHostedOptions);
}

private static void reportUserException(Throwable e, OptionValues parsedHostedOptions, Consumer<String> report) {
private static void reportUserException(Throwable e, OptionValues parsedHostedOptions) {
if (e instanceof UserException ue) {
for (String message : ue.getMessages()) {
report.accept(message);
reportUserError(message);
}
} else {
report.accept(e.getMessage());
reportUserError(e.getMessage());
}
Throwable current = e.getCause();
while (current != null) {
System.out.print("Caused by: ");
current.printStackTrace(System.out);
current = current.getCause();
}
if (parsedHostedOptions != null && NativeImageOptions.ReportExceptionStackTraces.getValue(parsedHostedOptions)) {
e.printStackTrace();
System.out.print("Internal exception: ");
e.printStackTrace(System.out);
}
System.out.flush();
}

public int build(ImageClassLoader imageClassLoader) {
Expand Down

0 comments on commit c62f53a

Please sign in to comment.