Skip to content
Snippets Groups Projects
Commit 90cd24b4 authored by Florian Angerer's avatar Florian Angerer
Browse files

Refine internal error reporting.

parent ca905ad8
No related branches found
No related tags found
No related merge requests found
...@@ -415,9 +415,7 @@ public class RDeparse { ...@@ -415,9 +415,7 @@ public class RDeparse {
} }
} }
} catch (AccessDeniedException | FileAlreadyExistsException | IllegalArgumentException e) { } catch (AccessDeniedException | FileAlreadyExistsException | IllegalArgumentException e) {
fixupSourcesTextInternal(); // do not report because these exceptions are legitimate
} catch (IOException e) {
RInternalError.reportError(e);
fixupSourcesTextInternal(); fixupSourcesTextInternal();
} catch (Throwable e) { } catch (Throwable e) {
RInternalError.reportError(e); RInternalError.reportError(e);
......
...@@ -45,6 +45,8 @@ import com.oracle.truffle.r.runtime.context.RContext; ...@@ -45,6 +45,8 @@ import com.oracle.truffle.r.runtime.context.RContext;
*/ */
public final class RInternalError extends Error implements TruffleException { public final class RInternalError extends Error implements TruffleException {
private static final String FASTR_ERRORS_LOG = "fastr_errors.log";
private static final long serialVersionUID = 80698622974155216L; private static final long serialVersionUID = 80698622974155216L;
private static boolean initializing = false; private static boolean initializing = false;
...@@ -154,20 +156,24 @@ public final class RInternalError extends Error implements TruffleException { ...@@ -154,20 +156,24 @@ public final class RInternalError extends Error implements TruffleException {
@TruffleBoundary @TruffleBoundary
public static void reportErrorAndConsoleLog(Throwable throwable, int contextId) { public static void reportErrorAndConsoleLog(Throwable throwable, int contextId) {
reportError(throwable, contextId); reportErrorDefault(throwable, contextId);
} }
@TruffleBoundary @TruffleBoundary
public static void reportError(Throwable t) { public static void reportError(Throwable t) {
String message = t instanceof RInternalError && t.getMessage() != null && !t.getMessage().isEmpty() ? t.getMessage() : "internal error: " + t.getClass().getSimpleName(); reportErrorDefault(t, 0);
reportError(message, t, 0); }
@TruffleBoundary
private static void reportErrorDefault(Throwable t, int contextId) {
String errMsg = t instanceof RInternalError && t.getMessage() != null && !t.getMessage().isEmpty() ? t.getMessage() : t.getClass().getSimpleName();
reportError(errMsg, t, contextId);
} }
private static void reportError(String message, Throwable throwable, int contextId) { private static void reportError(String errMsg, Throwable throwable, int contextId) {
try { try {
Throwable t = throwable; Throwable t = throwable;
if (FastROptions.PrintErrorStacktracesToFile.getBooleanValue() || FastROptions.PrintErrorStacktraces.getBooleanValue()) { if (FastROptions.PrintErrorStacktracesToFile.getBooleanValue() || FastROptions.PrintErrorStacktraces.getBooleanValue()) {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
t.printStackTrace(new PrintStream(out)); t.printStackTrace(new PrintStream(out));
String verboseStackTrace; String verboseStackTrace;
...@@ -185,9 +191,15 @@ public final class RInternalError extends Error implements TruffleException { ...@@ -185,9 +191,15 @@ public final class RInternalError extends Error implements TruffleException {
System.err.println(out.toString()); System.err.println(out.toString());
System.err.println(verboseStackTrace); System.err.println(verboseStackTrace);
} }
String message = "An internal error occurred: \"" + errMsg + "\"\nPlease report an issue including the commands";
if (FastROptions.PrintErrorStacktracesToFile.getBooleanValue()) {
message += " and the error log file '" + getLogFileName(contextId) + "'.";
} else {
message += ".";
}
if (FastROptions.PrintErrorStacktracesToFile.getBooleanValue()) { if (FastROptions.PrintErrorStacktracesToFile.getBooleanValue()) {
String suffix = contextId == 0 ? "" : "-" + Integer.toString(contextId); Path logfile = Utils.getLogPath(getLogFileName(contextId));
Path logfile = Utils.getLogPath("fastr_errors.log" + suffix);
try (BufferedWriter writer = Files.newBufferedWriter(logfile, StandardCharsets.UTF_8, StandardOpenOption.APPEND, try (BufferedWriter writer = Files.newBufferedWriter(logfile, StandardCharsets.UTF_8, StandardOpenOption.APPEND,
StandardOpenOption.CREATE)) { StandardOpenOption.CREATE)) {
writer.append(new Date().toString()).append('\n'); writer.append(new Date().toString()).append('\n');
...@@ -196,7 +208,7 @@ public final class RInternalError extends Error implements TruffleException { ...@@ -196,7 +208,7 @@ public final class RInternalError extends Error implements TruffleException {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
System.err.println(message + " (see fastr_errors.log" + suffix + ")"); System.err.println(message);
if (RContext.isEmbedded()) { if (RContext.isEmbedded()) {
RSuicide.rSuicide("FastR internal error"); RSuicide.rSuicide("FastR internal error");
} }
...@@ -211,6 +223,10 @@ public final class RInternalError extends Error implements TruffleException { ...@@ -211,6 +223,10 @@ public final class RInternalError extends Error implements TruffleException {
} }
} }
private static String getLogFileName(int contextId) {
return contextId == 0 ? FASTR_ERRORS_LOG : FASTR_ERRORS_LOG + "-" + Integer.toString(contextId);
}
@Override @Override
public Node getLocation() { public Node getLocation() {
return null; return null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment