|
43 | 43 | import java.util.HashMap;
|
44 | 44 | import java.util.Iterator;
|
45 | 45 | import java.util.List;
|
46 |
| -import java.util.ListIterator; |
47 | 46 | import java.util.Map;
|
48 | 47 | import java.util.Set;
|
49 | 48 | import java.util.UUID;
|
|
57 | 56 | import org.graalvm.polyglot.Context.Builder;
|
58 | 57 | import org.graalvm.polyglot.Engine;
|
59 | 58 | import org.graalvm.polyglot.PolyglotException;
|
60 |
| -import org.graalvm.polyglot.PolyglotException.StackFrame; |
61 | 59 | import org.graalvm.polyglot.Source;
|
62 |
| -import org.graalvm.polyglot.SourceSection; |
63 | 60 | import org.graalvm.polyglot.Value;
|
64 | 61 | import org.graalvm.shadowed.org.jline.reader.UserInterruptException;
|
65 | 62 |
|
@@ -820,9 +817,7 @@ protected void launch(Builder contextBuilder) {
|
820 | 817 | evalNonInteractive(context, consoleHandler);
|
821 | 818 | rc = 0;
|
822 | 819 | } catch (PolyglotException e) {
|
823 |
| - if (!e.isExit()) { |
824 |
| - printPythonLikeStackTrace(e); |
825 |
| - } else { |
| 820 | + if (e.isExit()) { |
826 | 821 | rc = e.getExitStatus();
|
827 | 822 | }
|
828 | 823 | } catch (NoSuchFileException e) {
|
@@ -1007,41 +1002,6 @@ private static void printFileNotFoundException(NoSuchFileException e) {
|
1007 | 1002 | System.err.println(GraalPythonMain.class.getCanonicalName() + ": can't open file '" + e.getFile() + "': " + reason);
|
1008 | 1003 | }
|
1009 | 1004 |
|
1010 |
| - private static void printPythonLikeStackTrace(PolyglotException e) { |
1011 |
| - // If we're running through the launcher and an exception escapes to here, |
1012 |
| - // we didn't go through the Python code to print it. That may be because |
1013 |
| - // it's an exception from another language. In this case, we still would |
1014 |
| - // like to print it like a Python exception. |
1015 |
| - ArrayList<String> stack = new ArrayList<>(); |
1016 |
| - for (StackFrame frame : e.getPolyglotStackTrace()) { |
1017 |
| - if (frame.isGuestFrame()) { |
1018 |
| - StringBuilder sb = new StringBuilder(); |
1019 |
| - SourceSection sourceSection = frame.getSourceLocation(); |
1020 |
| - String rootName = frame.getRootName(); |
1021 |
| - if (sourceSection != null) { |
1022 |
| - sb.append(" "); |
1023 |
| - String path = sourceSection.getSource().getPath(); |
1024 |
| - if (path != null) { |
1025 |
| - sb.append("File "); |
1026 |
| - } |
1027 |
| - sb.append('"'); |
1028 |
| - sb.append(sourceSection.getSource().getName()); |
1029 |
| - sb.append("\", line "); |
1030 |
| - sb.append(sourceSection.getStartLine()); |
1031 |
| - sb.append(", in "); |
1032 |
| - sb.append(rootName); |
1033 |
| - stack.add(sb.toString()); |
1034 |
| - } |
1035 |
| - } |
1036 |
| - } |
1037 |
| - System.err.println("Traceback (most recent call last):"); |
1038 |
| - ListIterator<String> listIterator = stack.listIterator(stack.size()); |
1039 |
| - while (listIterator.hasPrevious()) { |
1040 |
| - System.err.println(listIterator.previous()); |
1041 |
| - } |
1042 |
| - System.err.println(e.getMessage()); |
1043 |
| - } |
1044 |
| - |
1045 | 1005 | private void evalNonInteractive(Context context, ConsoleHandler consoleHandler) throws IOException {
|
1046 | 1006 | // We need to setup the terminal even when not running the REPL because code may request
|
1047 | 1007 | // input from the terminal.
|
@@ -1253,15 +1213,13 @@ private int readEvalPrint(Context context, ConsoleHandler consoleHandler) {
|
1253 | 1213 | if (e.isExit()) {
|
1254 | 1214 | // usually from quit
|
1255 | 1215 | throw new ExitException(e.getExitStatus());
|
1256 |
| - } else if (e.isHostException()) { |
1257 |
| - // we continue the repl even though the system may be broken |
1258 |
| - lastStatus = 1; |
1259 |
| - System.out.println(e.getMessage()); |
1260 |
| - } else if (e.isInternalError()) { |
1261 |
| - System.err.println("An internal error occurred:"); |
1262 |
| - printPythonLikeStackTrace(e); |
1263 |
| - |
1264 |
| - // we continue the repl even though the system may be broken |
| 1216 | + } else if (e.isInternalError() || e.isHostException()) { |
| 1217 | + /* |
| 1218 | + * The stacktrace should have been printed above by |
| 1219 | + * TopLevelExceptionHandler. We continue the repl even though the |
| 1220 | + * system may be broken |
| 1221 | + */ |
| 1222 | + System.err.println("An internal error occurred, continue at your own risk"); |
1265 | 1223 | lastStatus = 1;
|
1266 | 1224 | } else if (e.isGuestException()) {
|
1267 | 1225 | // drop through to continue REPL and remember last eval was an error
|
|
0 commit comments