@@ -166,59 +166,63 @@ public static void reportError(Throwable t) {
166166
167167 @ TruffleBoundary
168168 private static void reportErrorDefault (Throwable t , int contextId ) {
169- String errMsg = t instanceof RInternalError && t .getMessage () != null && !t .getMessage ().isEmpty () ? t .getMessage () : t .getClass ().getSimpleName ();
169+ boolean detailedMessage = FastROptions .PrintErrorStacktraces .getBooleanValue () || FastROptions .PrintErrorStacktracesToFile .getBooleanValue ();
170+ String errMsg = "." ;
171+ if (detailedMessage ) {
172+ errMsg = ": \" " ;
173+ errMsg += t instanceof RInternalError && t .getMessage () != null && !t .getMessage ().isEmpty () ? t .getMessage () : t .getClass ().getSimpleName ();
174+ errMsg += "\" " ;
175+ }
170176 reportError (errMsg , t , contextId );
171177 }
172178
173179 private static void reportError (String errMsg , Throwable throwable , int contextId ) {
174180 try {
175181 Throwable t = throwable ;
176- if (FastROptions .PrintErrorStacktracesToFile .getBooleanValue () || FastROptions .PrintErrorStacktraces .getBooleanValue ()) {
177- ByteArrayOutputStream out = new ByteArrayOutputStream ();
178- t .printStackTrace (new PrintStream (out ));
179- String verboseStackTrace ;
180- if (t .getCause () != null && t instanceof IOException ) {
181- t = t .getCause ();
182- }
183- if (t instanceof RInternalError ) {
184- verboseStackTrace = ((RInternalError ) t ).getVerboseStackTrace ();
185- } else if (t instanceof RError ) {
186- verboseStackTrace = ((RError ) t ).getVerboseStackTrace ();
187- } else {
188- verboseStackTrace = "" ;
189- }
190- if (FastROptions .PrintErrorStacktraces .getBooleanValue ()) {
191- System .err .println (out .toString ());
192- System .err .println (verboseStackTrace );
193- }
182+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
183+ t .printStackTrace (new PrintStream (out ));
184+ String verboseStackTrace ;
185+ if (t .getCause () != null && t instanceof IOException ) {
186+ t = t .getCause ();
187+ }
188+ if (t instanceof RInternalError ) {
189+ verboseStackTrace = ((RInternalError ) t ).getVerboseStackTrace ();
190+ } else if (t instanceof RError ) {
191+ verboseStackTrace = ((RError ) t ).getVerboseStackTrace ();
192+ } else {
193+ verboseStackTrace = "" ;
194+ }
195+ if (FastROptions .PrintErrorStacktraces .getBooleanValue ()) {
196+ System .err .println (out .toString ());
197+ System .err .println (verboseStackTrace );
198+ }
194199
195- String message = "An internal error occurred: \" " + errMsg + "\" \n Please report an issue at https://github.com/oracle/fastr including the commands" ;
196- if (FastROptions .PrintErrorStacktracesToFile .getBooleanValue ()) {
197- Path logfile = Utils .getLogPath (getLogFileName (contextId ));
198- if (logfile != null ) {
199- message += " and the error log file '" + logfile + "'." ;
200- try (BufferedWriter writer = Files .newBufferedWriter (logfile , StandardCharsets .UTF_8 , StandardOpenOption .APPEND ,
201- StandardOpenOption .CREATE )) {
202- writer .append (new Date ().toString ()).append ('\n' );
203- writer .append (out .toString ()).append ('\n' );
204- writer .append (verboseStackTrace ).append ("\n \n " );
205- } catch (IOException e ) {
206- e .printStackTrace ();
207- }
208- } else {
209- message += ". Cannot write error log file (tried current working directory, user home directory, FastR home directory)." ;
210- }
211- System .err .println (message );
212- if (RContext .isEmbedded ()) {
213- RSuicide .rSuicide ("FastR internal error" );
200+ String message = "An internal error occurred" + errMsg + "\n Please report an issue at https://github.com/oracle/fastr including the commands" ;
201+ if (FastROptions .PrintErrorStacktracesToFile .getBooleanValue ()) {
202+ Path logfile = Utils .getLogPath (getLogFileName (contextId ));
203+ if (logfile != null ) {
204+ message += " and the error log file '" + logfile + "'." ;
205+ try (BufferedWriter writer = Files .newBufferedWriter (logfile , StandardCharsets .UTF_8 , StandardOpenOption .APPEND ,
206+ StandardOpenOption .CREATE )) {
207+ writer .append (new Date ().toString ()).append ('\n' );
208+ writer .append (out .toString ()).append ('\n' );
209+ writer .append (verboseStackTrace ).append ("\n \n " );
210+ } catch (IOException e ) {
211+ e .printStackTrace ();
214212 }
215213 } else {
216- message += ". You can rerun FastR with --jvm.DR:+" + FastROptions .PrintErrorStacktracesToFile .name () +
217- " to turn on internal errors logging. Please attach the log file to the issue if possible." ;
214+ message += ". Cannot write error log file (tried current working directory, user home directory, FastR home directory)." ;
218215 }
219- if (!FastROptions .PrintErrorStacktraces .getBooleanValue () && !FastROptions .PrintErrorStacktracesToFile .getBooleanValue ()) {
220- System .err .println (message );
216+ System .err .println (message );
217+ if (RContext .isEmbedded ()) {
218+ RSuicide .rSuicide ("FastR internal error" );
221219 }
220+ } else {
221+ message += ". You can rerun FastR with --jvm.DR:+" + FastROptions .PrintErrorStacktracesToFile .name () +
222+ " to turn on internal errors logging. Please attach the log file to the issue if possible." ;
223+ }
224+ if (!FastROptions .PrintErrorStacktraces .getBooleanValue () && !FastROptions .PrintErrorStacktracesToFile .getBooleanValue ()) {
225+ System .err .println (message );
222226 }
223227 } catch (ExitException | ThreadDeath t ) {
224228 throw t ;
0 commit comments