Skip to content

Commit

Permalink
Improve debugging (Exceptions...)
Browse files Browse the repository at this point in the history
- 'Filled tag x with y' will now watch out for tag escape symbols and
display them correctly.
- add dB.log(DebugElement) to replicate the echoDebug's similar
functionality
- change all 'exception.printStackTraces' to call a dB function that
manages it correctly and singularly.
  • Loading branch information
mcmonkey4eva committed Nov 16, 2013
1 parent 7571417 commit 668ee64
Show file tree
Hide file tree
Showing 40 changed files with 105 additions and 95 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -259,7 +259,7 @@ public void onEnable() {
try {
ObjectFetcher._registerCoreObjects();
} catch (Exception e) {
e.printStackTrace();
dB.echoError(e);
}

// Initialize non-standard dMaterials
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/aufdemrand/denizen/events/EventManager.java
Expand Up @@ -118,7 +118,7 @@ private static PluginCommand getCommand(String name, Plugin plugin) {

command = c.newInstance(name, plugin);
} catch (Exception e) {
e.printStackTrace();
dB.echoError(e);
}

return command;
Expand All @@ -135,13 +135,13 @@ private static CommandMap getCommandMap() {
commandMap = (CommandMap) f.get(Bukkit.getPluginManager());
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
dB.echoError(e);
} catch (SecurityException e) {
e.printStackTrace();
dB.echoError(e);
} catch (IllegalArgumentException e) {
e.printStackTrace();
dB.echoError(e);
} catch (IllegalAccessException e) {
e.printStackTrace();
dB.echoError(e);
}

return commandMap;
Expand Down
Expand Up @@ -2,6 +2,7 @@


import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.utilities.debugging.dB;
import org.bukkit.Bukkit;

import net.aufdemrand.denizen.Denizen;
Expand Down Expand Up @@ -33,11 +34,9 @@ public AbstractListener createInstance(dPlayer player, String listenerId) {
denizen.getListenerRegistry().addListenerFor(player, instanceClass.newInstance(), listenerId);
return denizen.getListenerRegistry().getListenerFor(player, listenerId);
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
dB.echoError(e);
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
dB.echoError(e);
}
return null;
}
Expand Down
Expand Up @@ -202,7 +202,7 @@ public void disableCoreMembers() {
member.onDisable();
} catch (Exception e) {
dB.echoError("Unable to disable '" + member.getClass().getName() + "'!");
if (dB.showStackTraces) e.printStackTrace();
dB.echoError(e);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/Element.java
Expand Up @@ -777,7 +777,8 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
"for tag <" + attribute.getOrigin() + ">!");
return "null";
} else {
dB.echoDebug(attribute.getScriptEntry(), "Filled tag <" + attribute.getOrigin() + "> with '" + element + "'.");
dB.echoDebug(attribute.getScriptEntry(), "Filled tag <" + attribute.getOrigin() + "> with '" +
element.replace((char)0x01, '<').replace((char)0x02, '>').replace(dList.internal_escape, "|") + "'.");
return element;
}
}
Expand Down
Expand Up @@ -89,7 +89,7 @@ public static boolean checkMatch(Class<? extends dObject> dClass, String value)
try {
return (Boolean) matches.get(dClass).invoke(null, value);
} catch (Exception e) {
e.printStackTrace();
dB.echoError(e);
}

return false;
Expand All @@ -100,7 +100,7 @@ public static dObject getObjectFrom(Class<? extends dObject> dClass, String valu
try {
return (dObject) valueof.get(dClass).invoke(null, value);
} catch (Exception e) {
e.printStackTrace();
dB.echoError(e);
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -753,7 +753,7 @@ else if (ent instanceof Villager) {
}

} catch (Exception e) {
e.printStackTrace();
dB.echoError(e);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dList.java
Expand Up @@ -218,7 +218,7 @@ public List<dObject> filter(Class<? extends dObject> dClass, ScriptEntry entry)
}
}
} catch (Exception e) {
e.printStackTrace();
dB.echoError(e);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/dMaterial.java
Expand Up @@ -7,6 +7,7 @@
import java.util.regex.Pattern;

import net.aufdemrand.denizen.utilities.Utilities;
import net.aufdemrand.denizen.utilities.debugging.dB;
import org.bukkit.Material;
import org.bukkit.material.MaterialData;

Expand Down Expand Up @@ -213,7 +214,7 @@ public static void _initialize() {
dMaterial mat = (dMaterial) field.get(null);
registerVariety(mat);
} catch (Exception e) {
e.printStackTrace();
dB.echoError(e);
}
}
}
Expand Down Expand Up @@ -316,7 +317,7 @@ public static dMaterial valueOf(String string) {
// Should be pretty safe, unless there's an enum without a matching field.
return (dMaterial) field.get(null);
} catch (Exception e) {
e.printStackTrace();
dB.echoError(e);
}
}
}
Expand Down
Expand Up @@ -76,9 +76,9 @@ public static String getPropertiesString(dObject object) {
}

} catch (IllegalAccessException e) {
e.printStackTrace();
dB.echoError(e);
} catch (InvocationTargetException e) {
e.printStackTrace();
dB.echoError(e);
}

// Return the list of properties
Expand All @@ -95,9 +95,9 @@ public static List<Property> getProperties(dObject object) {
}

} catch (IllegalAccessException e) {
e.printStackTrace();
dB.echoError(e);
} catch (InvocationTargetException e) {
e.printStackTrace();
dB.echoError(e);
}

return props;
Expand Down
Expand Up @@ -74,7 +74,7 @@ public static List<ScriptEntry> buildScriptEntries(List<String> contents, Script
ScriptEntry newEntry = new ScriptEntry(scriptEntry[0], args, parent).setPlayer(player).setNPC(npc);
scriptCommands.add(newEntry);
} catch (Exception e) {
if (dB.showStackTraces) e.printStackTrace();
dB.echoError(e);
}
}

Expand Down
12 changes: 4 additions & 8 deletions src/main/java/net/aufdemrand/denizen/scripts/ScriptHelper.java
Expand Up @@ -33,7 +33,7 @@ public static void reloadScripts() {
_yamlScripts.loadFromString(concatenated);
} catch (InvalidConfigurationException e) {
dB.echoError("Could not load scripts!");
e.printStackTrace();
dB.echoError(e);
}

// Remove all recipes added by Denizen item scripts
Expand Down Expand Up @@ -109,11 +109,7 @@ private static String _concatenateCoreScripts() {
} catch (RuntimeException e) {
dB.echoError(ChatColor.RED + "Woah! Error parsing " + fileName + "!");
HadAnError = true;
if (dB.showStackTraces) {
dB.log("STACKTRACE follows:");
e.printStackTrace();
}
else dB.log("Use '/denizen debug -s' for the nitty-gritty.");
dB.echoError(e);
}
}

Expand All @@ -124,10 +120,10 @@ private static String _concatenateCoreScripts() {
HadAnError = true;
}

} catch (Exception error) {
} catch (Exception e) {
dB.echoError(ChatColor.RED + "Woah! No script folder found in /plugins/Denizen/scripts/");
HadAnError = true;
if (dB.showStackTraces) error.printStackTrace();
dB.echoError(e);
}

return "";
Expand Down
Expand Up @@ -75,7 +75,7 @@ public static void _buildCoreYamlScriptContainers(FileConfiguration yamlScripts)
scriptContainers.put(scriptName, typeClass.getConstructor(ConfigurationSection.class, String.class)
.newInstance(ScriptHelper._gs().getConfigurationSection(scriptName), scriptName));
} catch (Exception e) {
e.printStackTrace();
dB.echoError(e);
}
}
}
Expand Down
Expand Up @@ -177,9 +177,7 @@ else if (arg.matchesPrefix("save") && !if_ignore) {

keepGoing = false;
dB.echoError("Woah! An exception has been called with this command!");
if (!dB.showStackTraces)
dB.echoError("Enable '/denizen stacktrace' for the nitty-gritty.");
else e.printStackTrace();
dB.echoError(e);
dB.echoDebug(scriptEntry, DebugElement.Footer);

} finally {
Expand All @@ -198,9 +196,7 @@ else if (arg.matchesPrefix("save") && !if_ignore) {
else dB.echoDebug(scriptEntry, "ScriptEntry has been cancelled.");
} catch (Exception e) {
dB.echoError("Woah!! An exception has been called with this command!");
if (!dB.showStackTraces)
dB.echoError("Enable '/denizen stacktrace' for the nitty-gritty.");
else e.printStackTrace();
dB.echoError(e);
}

}
Expand Down
Expand Up @@ -2430,7 +2430,7 @@ private <T extends AbstractCommand> void registerCoreMember(Class<T> cmd, String
cmd.newInstance().activate().as(name).withOptions(hint, args);
} catch(Exception e) {
dB.echoError("Could not register command " + name + ": " + e.getMessage());
if (dB.showStackTraces) e.printStackTrace();
dB.echoError(e);
}
}
}
Expand All @@ -2442,7 +2442,7 @@ public void disableCoreMembers() {
member.onDisable();
} catch (Exception e) {
dB.echoError("Unable to disable '" + member.getClass().getName() + "'!");
if (dB.showStackTraces) e.printStackTrace();
dB.echoError(e);
}
}

Expand Down
Expand Up @@ -70,7 +70,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
toAdd.getObjects().clear();
newEntries.add(toAdd);
} catch (Throwable e) {
e.printStackTrace();
dB.echoError(e);
}
}

Expand Down
Expand Up @@ -293,11 +293,7 @@ private void doCommand(ScriptEntry scriptEntry, String mapName) {

} catch (ScriptEntryCreationException e) {
dB.echoError("There has been a problem running the Command. Check syntax.");
if (dB.showStackTraces) {
dB.log("STACKTRACE follows:");
e.printStackTrace();
}
else dB.log("Use '/denizen debug -s' for the nitty-gritty.");
dB.echoError(e);
}
}

Expand Down
Expand Up @@ -65,7 +65,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

} catch (Exception e) {
dB.echoError("Uh oh! Report this to aufdemrand! Err: TagManagerObjectReflection");
e.printStackTrace();
dB.echoError(e);
}


Expand Down
Expand Up @@ -67,7 +67,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
newEntries.add(toAdd);
}
catch (Throwable e) {
e.printStackTrace();
dB.echoError(e);
}
}
ScriptQueue queue = new InstantQueue(queueId);
Expand Down
Expand Up @@ -130,7 +130,7 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept
try {
yamls.get(id.toUpperCase()).save(new File(DenizenAPI.getCurrentInstance().getDataFolder(), filename.asString()));
} catch (IOException e) {
e.printStackTrace();
dB.echoError(e);
}
}
break;
Expand Down
Expand Up @@ -155,7 +155,7 @@ public void run() {
execute(scriptEntry);
} catch (CommandExecutionException e) {
dB.echoError("Could not run delayed task!");
if (dB.showStackTraces) e.printStackTrace();
dB.echoError(e);
}
}
}, delay));
Expand Down
Expand Up @@ -74,7 +74,10 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
if (duration > 0) {
if (durations.containsKey(dNPC.getCitizen().getId() + pauseType.name())) {
try { denizen.getServer().getScheduler().cancelTask(durations.get(dNPC.getCitizen().getId() + pauseType.name())); }
catch (Exception e) { dB.echoError("There was an error pausing that!"); e.printStackTrace(); }
catch (Exception e) {
dB.echoError("There was an error pausing that!");
dB.echoError(e);
}

}
dB.echoDebug(scriptEntry, "Running delayed task: Unpause " + pauseType.toString());
Expand Down
Expand Up @@ -117,7 +117,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Just print the stacktrace if anything else, so we can debug other possible
// problems.
else
e.printStackTrace();
dB.echoError(e);

// Deconstruct the listener in case it was partially created while erroring out.
try { denizen.getListenerRegistry().getListenerFor(scriptEntry.getPlayer(), id.asString()).cancel(); }
Expand Down
Expand Up @@ -33,9 +33,7 @@ public dEntity getEntityFrom(Player player, dNPC npc) {

} catch (Exception e) {
dB.echoError("Woah! An exception has been called with this entity script!");
if (!dB.showStackTraces)
dB.echoError("Enable '/denizen stacktrace' for the nitty-gritty.");
else e.printStackTrace();
dB.echoError(e);
entity = null;
}

Expand Down
Expand Up @@ -109,11 +109,10 @@ public static InteractScriptContainer getInteractScript(dNPC npc, dPlayer player
} catch (Exception e) {
// Had a problem checking requirements, most likely a Legacy Requirement with bad syntax. Alert the console!
dB.echoError(ChatColor.RED + "'" + entry + "' has a bad requirement, skipping.");
if (!dB.showStackTraces) dB.echoError("Enable '/denizen stacktrace' for the nitty-gritty.");
else e.printStackTrace();
dB.echoError(e);
}

dB.log(dB.DebugElement.Spacer.toString()); // TODO: ???? toString(), or...?
dB.log(dB.DebugElement.Spacer, null);
// Next entry!
}

Expand Down
Expand Up @@ -122,9 +122,7 @@ else if (dItem.matches(m.group(2))) {
}
catch (Exception e) {
dB.echoError("Woah! An exception has been called with this inventory script!");
if (!dB.showStackTraces)
dB.echoError("Enable '/denizen stacktrace' for the nitty-gritty.");
else e.printStackTrace();
dB.echoError(e);
inventory = null;
}

Expand Down
Expand Up @@ -245,9 +245,7 @@ public dItem getItemFrom(dPlayer player, dNPC npc) {

} catch (Exception e) {
dB.echoError("Woah! An exception has been called with this item script!");
if (!dB.showStackTraces)
dB.echoError("Enable '/denizen stacktrace' for the nitty-gritty.");
else e.printStackTrace();
dB.echoError(e);
stack = null;
}

Expand Down
Expand Up @@ -2918,11 +2918,11 @@ public String call() {
determination = event.isAsynchronous() ? Bukkit.getScheduler().callSyncMethod(DenizenAPI.getCurrentInstance(), call).get() : call.call();
} catch (InterruptedException e) {
// TODO: Need to find a way to fix this eventually
// e.printStackTrace();
// dB.echoError(e);
} catch (ExecutionException e) {
e.printStackTrace();
dB.echoError(e);
} catch (Exception e) {
e.printStackTrace();
dB.echoError(e);
}

if (determination == null)
Expand Down

0 comments on commit 668ee64

Please sign in to comment.