4242import java .util .ServiceLoader ;
4343import java .util .Set ;
4444import java .util .TimerTask ;
45- import java .util .function .Consumer ;
4645import java .util .stream .Collectors ;
4746
4847import org .graalvm .collections .Pair ;
@@ -540,7 +539,7 @@ private int buildImage(ImageClassLoader classLoader) {
540539 NativeImageGeneratorRunner .reportFatalError (e , "FallbackImageRequest while building fallback image." );
541540 return ExitStatus .BUILDER_ERROR .getValue ();
542541 }
543- reportUserException (e , parsedHostedOptions , LogUtils :: warning );
542+ reportUserException (e , parsedHostedOptions );
544543 return ExitStatus .FALLBACK_IMAGE .getValue ();
545544 } catch (ParsingError e ) {
546545 NativeImageGeneratorRunner .reportFatalError (e );
@@ -567,7 +566,7 @@ private int buildImage(ImageClassLoader classLoader) {
567566 }
568567
569568 if (pee .getExceptions ().size () > 1 ) {
570- System .err .println (pee .getExceptions ().size () + " fatal errors detected:" );
569+ System .out .println (pee .getExceptions ().size () + " fatal errors detected:" );
571570 }
572571 for (Throwable exception : pee .getExceptions ()) {
573572 NativeImageGeneratorRunner .reportFatalError (exception );
@@ -653,8 +652,8 @@ public static void printCPUFeatures(Platform platform) {
653652 * @param e error to be reported.
654653 */
655654 protected static void reportFatalError (Throwable e ) {
656- System .err .print ("Fatal error: " );
657- e .printStackTrace ();
655+ System .out .print ("Fatal error: " );
656+ e .printStackTrace (System . out );
658657 }
659658
660659 /**
@@ -664,8 +663,8 @@ protected static void reportFatalError(Throwable e) {
664663 * @param msg message to report.
665664 */
666665 protected static void reportFatalError (Throwable e , String msg ) {
667- System .err .print ("Fatal error: " + msg );
668- e .printStackTrace ();
666+ System .out .print ("Fatal error: " + msg );
667+ e .printStackTrace (System . out );
669668 }
670669
671670 /**
@@ -674,7 +673,7 @@ protected static void reportFatalError(Throwable e, String msg) {
674673 * @param msg error message that is printed.
675674 */
676675 public static void reportUserError (String msg ) {
677- System .err .println ("Error: " + msg );
676+ System .out .println ("Error: " + msg );
678677 }
679678
680679 /**
@@ -684,20 +683,28 @@ public static void reportUserError(String msg) {
684683 * @param parsedHostedOptions
685684 */
686685 public static void reportUserError (Throwable e , OptionValues parsedHostedOptions ) {
687- reportUserException (e , parsedHostedOptions , NativeImageGeneratorRunner :: reportUserError );
686+ reportUserException (e , parsedHostedOptions );
688687 }
689688
690- private static void reportUserException (Throwable e , OptionValues parsedHostedOptions , Consumer < String > report ) {
689+ private static void reportUserException (Throwable e , OptionValues parsedHostedOptions ) {
691690 if (e instanceof UserException ue ) {
692691 for (String message : ue .getMessages ()) {
693- report . accept (message );
692+ reportUserError (message );
694693 }
695694 } else {
696- report .accept (e .getMessage ());
695+ reportUserError (e .getMessage ());
696+ }
697+ Throwable current = e .getCause ();
698+ while (current != null ) {
699+ System .out .print ("Caused by: " );
700+ current .printStackTrace (System .out );
701+ current = current .getCause ();
697702 }
698703 if (parsedHostedOptions != null && NativeImageOptions .ReportExceptionStackTraces .getValue (parsedHostedOptions )) {
699- e .printStackTrace ();
704+ System .out .print ("Internal exception: " );
705+ e .printStackTrace (System .out );
700706 }
707+ System .out .flush ();
701708 }
702709
703710 public int build (ImageClassLoader imageClassLoader ) {
0 commit comments