From ca905ad861f864f42e5bf11263a9e72cd48c8ff3 Mon Sep 17 00:00:00 2001
From: Florian Angerer <florian.angerer@oracle.com>
Date: Fri, 23 Mar 2018 13:42:43 +0100
Subject: [PATCH] Accept custom message for 'RInternalError.reportError'.

---
 .../src/com/oracle/truffle/r/runtime/RDeparse.java        | 5 +++--
 .../src/com/oracle/truffle/r/runtime/RInternalError.java  | 8 ++++----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java
index 9de478bc49..29b6af3ec5 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java
@@ -419,8 +419,9 @@ public class RDeparse {
             } catch (IOException e) {
                 RInternalError.reportError(e);
                 fixupSourcesTextInternal();
-            } catch (NoSuchAlgorithmException e) {
-                throw RInternalError.shouldNotReachHere("SHA-256 is an unknown algorithm");
+            } catch (Throwable e) {
+                RInternalError.reportError(e);
+                fixupSourcesTextInternal();
             }
         }
 
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RInternalError.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RInternalError.java
index 97a9ef4253..7ba302c0e9 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RInternalError.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RInternalError.java
@@ -158,11 +158,12 @@ public final class RInternalError extends Error implements TruffleException {
     }
 
     @TruffleBoundary
-    public static void reportError(Throwable throwable) {
-        reportError(throwable, 0);
+    public static void reportError(Throwable t) {
+        String message = t instanceof RInternalError && t.getMessage() != null && !t.getMessage().isEmpty() ? t.getMessage() : "internal error: " + t.getClass().getSimpleName();
+        reportError(message, t, 0);
     }
 
-    private static void reportError(Throwable throwable, int contextId) {
+    private static void reportError(String message, Throwable throwable, int contextId) {
         try {
             Throwable t = throwable;
             if (FastROptions.PrintErrorStacktracesToFile.getBooleanValue() || FastROptions.PrintErrorStacktraces.getBooleanValue()) {
@@ -184,7 +185,6 @@ public final class RInternalError extends Error implements TruffleException {
                     System.err.println(out.toString());
                     System.err.println(verboseStackTrace);
                 }
-                String message = t instanceof RInternalError && t.getMessage() != null && !t.getMessage().isEmpty() ? t.getMessage() : "internal error: " + t.getClass().getSimpleName();
                 if (FastROptions.PrintErrorStacktracesToFile.getBooleanValue()) {
                     String suffix = contextId == 0 ? "" : "-" + Integer.toString(contextId);
                     Path logfile = Utils.getLogPath("fastr_errors.log" + suffix);
-- 
GitLab