Permalink
Browse files

Properly pass column information through the exception system

Previously, the causedBy section of the exceptions were not properly
printed in the default unhandled exception handler. Now, the column
information that is passed through is properly printed (though I think
the column information itself is still not accurate, but this is a
problem in the compiler, not the exception system). Also added "at" to
the beginning of each stack trace line, which brings the format more in
line with other languages stacktrace prints.
  • Loading branch information...
LadyCailin committed Dec 4, 2018
1 parent b24b6dc commit 06fe308a5522b34a734af065049d1567a5340396
@@ -128,7 +128,7 @@ public static AbstractCREException getFromCArray(CArray exception, Target t) thr
CArray stElement = Static.getArray(consStElement, t);
int line = Static.getInt32(stElement.get("line", t), t);
File f = new File(stElement.get("file", t).val());
int col = 0; //
int col = Static.getInt32(stElement.get("col", t), t);
st.add(new StackTraceElement(stElement.get("id", t).val(), new Target(line, f, col)));
}
// Now we have parsed everything into POJOs
@@ -191,15 +191,15 @@ private static void PrintMessage(StringBuilder log, StringBuilder console, Strin
simplepath = file.getName();
}
log.append("\t").append(proc).append(":").append(filepath).append(":")
log.append("\tat ").append(proc).append(":").append(filepath).append(":")
.append(line).append(".")
.append(column).append("\n");
console.append("\t").append(TermColors.GREEN).append(proc)
console.append("\t").append(TermColors.WHITE).append("at ").append(TermColors.GREEN).append(proc)
.append(TermColors.WHITE).append(":")
.append(TermColors.YELLOW).append(filepath)
.append(TermColors.WHITE).append(":")
.append(TermColors.CYAN).append(line).append(".").append(column).append("\n");
player.append("\t").append(MCChatColor.GREEN).append(proc)
player.append("\t").append(MCChatColor.WHITE).append("at ").append(MCChatColor.GREEN).append(proc)
.append(MCChatColor.WHITE).append(":")
.append(MCChatColor.YELLOW).append(simplepath)
.append(MCChatColor.WHITE).append(":")
@@ -258,7 +258,7 @@ private static void DoReport(String message, String exceptionType, ConfigRuntime
CArray element = Static.getArray(consElement, t);
int line = Static.getInt32(element.get("line", t), t);
File file = new File(element.get("file", t).val());
int col = element.getColumn();
int col = Static.getInt32(element.get("col", t), t);
Target stElementTarget = new Target(line, file, col);
newSt.add(new StackTraceElement(element.get("id", t).val(), stElementTarget));
}
@@ -533,6 +533,7 @@ public CArray getObjectFor() {
element.set("file", name);
}
element.set("line", new CInt(getDefinedAt().line(), Target.UNKNOWN), Target.UNKNOWN);
element.set("col", new CInt(getDefinedAt().col(), Target.UNKNOWN), Target.UNKNOWN);
return element;
}
@@ -77,7 +77,7 @@ public void testExceptionObjectCorrect() throws Exception {
/* 3 */ + "} catch (IOException @e){ \n"
/* 4 */ + "msg(@e); \n"
/* 5 */ + "}", fakePlayer);
verify(fakePlayer).sendMessage("{causedBy: null, classType: ms.lang.IOException, message: message, stackTrace: {{file: Unknown file, id: <<main code>>, line: 2}}}");
verify(fakePlayer).sendMessage("{causedBy: null, classType: ms.lang.IOException, message: message, stackTrace: {{col: 2, file: Unknown file, id: <<main code>>, line: 2}}}");
}
@Test
@@ -100,10 +100,10 @@ public void testExceptionObjectCorrect2() throws Exception {
/* 14 */ + "}", fakePlayer);
verify(fakePlayer).sendMessage("{causedBy: null, classType: ms.lang.IOException, message: message, stackTrace:"
+ " {"
+ "{file: Unknown file, id: proc _c, line: 8}, "
+ "{file: Unknown file, id: proc _b, line: 5}, "
+ "{file: Unknown file, id: proc _a, line: 2}, "
+ "{file: Unknown file, id: <<main code>>, line: 11}}"
+ "{col: 2, file: Unknown file, id: proc _c, line: 8}, "
+ "{col: 2, file: Unknown file, id: proc _b, line: 5}, "
+ "{col: 2, file: Unknown file, id: proc _a, line: 2}, "
+ "{col: 2, file: Unknown file, id: <<main code>>, line: 11}}"
+ "}");
}
@@ -127,10 +127,10 @@ public void testExceptionObjectCorrect3() throws Exception {
/* 14 */ + "}", fakePlayer);
verify(fakePlayer).sendMessage("{causedBy: null, classType: ms.lang.RangeException, message: Division by 0!, stackTrace:"
+ " {"
+ "{file: Unknown file, id: proc _c, line: 8}, "
+ "{file: Unknown file, id: proc _b, line: 5}, "
+ "{file: Unknown file, id: proc _a, line: 2}, "
+ "{file: Unknown file, id: <<main code>>, line: 11}}"
+ "{col: 12, file: Unknown file, id: proc _c, line: 8}, "
+ "{col: 2, file: Unknown file, id: proc _b, line: 5}, "
+ "{col: 2, file: Unknown file, id: proc _a, line: 2}, "
+ "{col: 2, file: Unknown file, id: <<main code>>, line: 11}}"
+ "}");
}
@@ -257,14 +257,17 @@ public void testCausedBy() throws Exception {
+ "message: original, "
+ "stackTrace: {"
+ "{"
+ "col: 4, "
+ "file: Unknown file, "
+ "id: proc _a, "
+ "line: 2"
+ "}, {"
+ "col: 4, "
+ "file: Unknown file, "
+ "id: proc _b, "
+ "line: 5"
+ "}, {"
+ "col: 5, "
+ "file: Unknown file, "
+ "id: <<main code>>, "
+ "line: 9"
@@ -275,6 +278,7 @@ public void testCausedBy() throws Exception {
+ "message: new, "
+ "stackTrace: {"
+ "{"
+ "col: 5, "
+ "file: Unknown file, "
+ "id: <<main code>>, "
+ "line: 11"

0 comments on commit 06fe308

Please sign in to comment.