Skip to content

Commit

Permalink
server.stack_trace tag
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 23, 2021
1 parent 62ab097 commit 0b0d28a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Expand Up @@ -2291,6 +2291,20 @@ else if (attribute.startsWith("generate_loot_table") && attribute.hasContext(1))
}
event.setReplacedObject(result.getObjectAttribute(attribute.fulfill(1)));
}

// <--[tag]
// @attribute <server.stack_trace>
// @returns ElementTag
// @description
// Generates and shows a stack trace for the current context.
// This tag is strictly for internal debugging reasons.
// WARNING: Different Java versions generate different stack trace formats and details.
// WARNING: Java internally limits stack trace generation in a variety of ways. This tag cannot be relied on to output anything.
// -->
else if (attribute.startsWith("stack_trace")) {
String trace = com.denizenscript.denizen.utilities.debugging.Debug.getFullExceptionMessage(new RuntimeException("TRACE"), false);
event.setReplacedObject(new ElementTag(trace).getObjectAttribute(attribute.fulfill(1)));
}
}

public static void listDeprecateWarn(Attribute attribute) {
Expand Down
Expand Up @@ -264,7 +264,7 @@ public static void echoError(ScriptQueue source, Throwable ex) {
if (source == null) {
source = CommandExecutor.currentQueue;
}
String errorMessage = getFullExceptionMessage(ex);
String errorMessage = getFullExceptionMessage(ex, true);
if (throwErrorEvent) {
throwErrorEvent = false;
Throwable thrown = ex;
Expand Down Expand Up @@ -293,10 +293,12 @@ public static void echoError(ScriptQueue source, Throwable ex) {
throwErrorEvent = wasThrown;
}

public static String getFullExceptionMessage(Throwable ex) {
public static String getFullExceptionMessage(Throwable ex, boolean includeBounding) {
StringBuilder errorMessage = new StringBuilder();
errorMessage.append("Internal exception was thrown!\n");
String prefix = ChatColor.GRAY + "[Error Continued] " + ChatColor.WHITE;
if (includeBounding) {
errorMessage.append("Internal exception was thrown!\n");
}
String prefix = includeBounding ? ChatColor.GRAY + "[Error Continued] " + ChatColor.WHITE : "";
boolean first = true;
while (ex != null) {
errorMessage.append(prefix);
Expand All @@ -305,7 +307,7 @@ public static String getFullExceptionMessage(Throwable ex) {
}
errorMessage.append(ex.toString()).append("\n");
for (StackTraceElement ste : ex.getStackTrace()) {
errorMessage.append(prefix).append(ste.toString()).append("\n");
errorMessage.append(prefix).append(" ").append(ste.toString()).append("\n");
}
if (ex.getCause() == ex) {
break;
Expand Down

0 comments on commit 0b0d28a

Please sign in to comment.