Skip to content

Commit

Permalink
error handling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 25, 2021
1 parent f5c2b22 commit cfee015
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2387,19 +2387,6 @@ public ObjectTag setPrefix(String prefix) {
}
@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
if (!attribute.hasAlternative()) {
Debug.echoDebug(attribute.getScriptEntry(), "Unfilled attributes '" + attribute.unfilledString() +
"' for tag <" + attribute.getOrigin() + ">!");
if (attribute.seemingSuccesses.size() > 0) {
String almost = attribute.seemingSuccesses.get(attribute.seemingSuccesses.size() - 1);
if (attribute.hasContextFailed) {
Debug.echoDebug(attribute.getScriptEntry(), "Almost matched but failed (missing [context] parameter?): " + almost);
}
else {
Debug.echoDebug(attribute.getScriptEntry(), "Almost matched but failed (possibly bad input?): " + almost);
}
}
}
if (Debug.verbose) {
Debug.log("Element - Unfilled! Null!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static <P extends Property> void registerTag(String name, PropertyTag<P>
Property prop = getter.get(object);
if (prop == null) {
if (!attribute.hasAlternative()) {
Debug.echoError("Property '" + propertyClass.getSimpleName() + "' does not describe the input object.");
attribute.echoError("Property '" + propertyClass.getSimpleName() + "' does not describe the input object.");
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ else if (callback != null && callback.asBoolean()) {
else {
List<BracedData> bdlist = (List<BracedData>) scriptEntry.getObject("braces");
if (bdlist == null || bdlist.isEmpty()) {
Debug.echoError(scriptEntry.getResidingQueue(), "Empty braces (internal)!");
Debug.echoError(scriptEntry.getResidingQueue(), "Empty subsection - did you forget a ':'?");
return;
}
List<ScriptEntry> bracedCommandsList = bdlist.get(0).value;
if (bracedCommandsList == null || bracedCommandsList.isEmpty()) {
Debug.echoError(scriptEntry.getResidingQueue(), "Empty braces!");
Debug.echoError(scriptEntry.getResidingQueue(), "Empty subsection - did you forget to add the sub-commands inside the command?");
return;
}
if (scriptEntry.dbCallShouldDebug()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,12 @@ else if (callback != null && callback.asBoolean()) {
else {
List<BracedCommand.BracedData> data = ((List<BracedCommand.BracedData>) scriptEntry.getObject("braces"));
if (data == null || data.isEmpty()) {
Debug.echoError(scriptEntry.getResidingQueue(), "Empty braces (internal)!");
Debug.echoError(scriptEntry.getResidingQueue(), "Empty braces!");
Debug.echoError(scriptEntry.getResidingQueue(), "Empty subsection - did you forget a ':'?");
return;
}
List<ScriptEntry> bracedCommandsList = data.get(0).value;
if (bracedCommandsList == null || bracedCommandsList.isEmpty()) {
Debug.echoError("Empty braces!");
Debug.echoError(scriptEntry.getResidingQueue(), "Empty subsection - did you forget to add the sub-commands inside the command?");
return;
}
if (scriptEntry.dbCallShouldDebug()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ else if (callback != null && callback.asBoolean()) {
List<String> comparisons = (List<String>) scriptEntry.getObject("comparisons");
List<BracedData> data = ((List<BracedData>) scriptEntry.getObject("braces"));
if (data == null || data.isEmpty()) {
Debug.echoError(scriptEntry.getResidingQueue(), "Empty braces (internal)!");
Debug.echoError(scriptEntry.getResidingQueue(), "Empty subsection - did you forget a ':'?");
return;
}
List<ScriptEntry> bracedCommandsList = data.get(0).value;

if (bracedCommandsList == null || bracedCommandsList.isEmpty()) {
Debug.echoError(scriptEntry.getResidingQueue(), "Empty braces!");
Debug.echoError(scriptEntry.getResidingQueue(), "Empty subsection - did you forget to add the sub-commands inside the command?");
return;
}
boolean run = new IfCommand.ArgComparer().compare(comparisons, scriptEntry);
Expand Down
26 changes: 21 additions & 5 deletions src/main/java/com/denizenscript/denizencore/tags/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ else if (chr == '.' && !(x > 0 && isNumber(attrInp[x + 1]) && isNumber(attrInp[x
public boolean hasContextFailed = false;

public void resetErrorTrack() {
if (Debug.verbose) {
Debug.echoError("(Verbose) Attribute - error track reset");
}
seemingSuccesses.clear();
hasContextFailed = false;
}
Expand Down Expand Up @@ -142,10 +145,10 @@ public boolean startsWith(String string) {
if (fulfilled >= attributes.length) {
return false;
}
if (Debug.verbose) {
Debug.log("Trying tag startsWith " + string + " on tag " + toString());
}
if (string.indexOf('.') >= 0) {
if (Debug.verbose) {
Debug.log("Trying tag startsWith " + string + " on tag " + toString());
}
List<String> tmp = CoreUtilities.split(string, '.');
if (tmp.size() + fulfilled > attributes.length) {
return false;
Expand All @@ -155,10 +158,16 @@ public boolean startsWith(String string) {
return false;
}
}
if (Debug.verbose) {
Debug.log("Chain-Tag found!");
}
seemingSuccesses.add(string);
return true;
}
if (attributes[fulfilled].key.equals(string)) {
if (Debug.verbose) {
Debug.log("Sub-tag found!");
}
seemingSuccesses.add(string);
return true;
}
Expand Down Expand Up @@ -189,6 +198,9 @@ public boolean hasContext(int attribute) {
if (attributes[attribute].context != null) {
return true;
}
if (Debug.verbose) {
Debug.log("Attribute " + attribute + " is missing context, hasContextFailed");
}
hasContextFailed = true;
return false;
}
Expand Down Expand Up @@ -443,11 +455,15 @@ public String unfilledString() {
public String toString() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < attributes.length; i++) {
sb.append(i < fulfilled ? "<GR>" : (i == fulfilled ? "<R>" : "<Y>")).append(attributes[i].key);
if (contexts[i] != null) {
sb.append(attributes[i].key).append("[").append(contexts[i]).append("].");
sb.append("<LG>[<A>").append(contexts[i]).append("<LG>].");
}
else if (attributes[i].context != null) {
sb.append("<LG>[<R>").append(attributes[i].context).append("<LG>].");
}
else {
sb.append(attributes[i].toString()).append(".");
sb.append("<LG>.");
}
}
if (sb.length() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ public ObjectTag getObjectAttribute(T object, Attribute attribute) {
ObjectTag returned;
TagRunnable.ObjectInterface<T> otr = registeredObjectTags.get(attrLow);
if (otr != null) {
if (Debug.verbose) {
Debug.log("TagProcessor - Sub-tag found for " + attrLow);
}
attribute.seemingSuccesses.add(attrLow);
returned = otr.run(attribute, object);
if (returned == null) {
if (Debug.verbose) {
Debug.log("TagProcessor - result was null");
}
return null;
}
return returned.getObjectAttribute(attribute.fulfill(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,6 @@ public void setReplaced(String string) {
wasReplaced = string != null;
}

public boolean hasScriptEntryAttached() {
return context.entry != null;
}

public ScriptEntry getScriptEntry() {
return context.entry;
}
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/denizenscript/denizencore/tags/TagManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,27 @@ public static ObjectTag readSingleTagObject(TagContext context, ReplaceableTagEv
}
if (!event.replaced()) {
ScriptQueue queue = context.entry != null ? context.entry.getResidingQueue() : null;
String tagStr = "<" + event.toString() + ">";
String tagStr = "<LG><" + event.toString() + "<LG>><W>";
Debug.echoError(queue, "Tag " + tagStr + " is invalid!");
recentTagError = true;
if (OBJECTTAG_CONFUSION_PATTERN.matcher(tagStr).matches()) {
Debug.echoError(queue, "'ObjectTag' notation is for documentation purposes, and not to be used literally."
+ " An actual object must be inserted instead. If confused, join our Discord at https://discord.gg/Q6pZGSR to ask for help!");
}
if (!event.hasAlternative()) {
if (event.getAttributes().fulfilled < event.getAttributes().attributes.length) {
Debug.echoDebug(event.getScriptEntry(), " Unfilled or unrecognized sub-tag(s) '<R>" + event.getAttributes().unfilledString() + "<W>' for tag <LG><" + event.getAttributes().origin + "<LG>><W>!");
if (event.getAttributes().seemingSuccesses.size() > 0) {
String almost = event.getAttributes().seemingSuccesses.get(event.getAttributes().seemingSuccesses.size() - 1);
if (event.getAttributes().hasContextFailed) {
Debug.echoDebug(event.getScriptEntry(), " Almost matched but failed (missing [context] parameter?): " + almost);
}
else {
Debug.echoDebug(event.getScriptEntry(), " Almost matched but failed (possibly bad input?): " + almost);
}
}
}
}
return new ElementTag(event.raw_tag);
}
return event.getReplacedObj();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public static ObjectTag autoAttribTyped(ObjectTag inp, Attribute attribute) {

public static ObjectTag autoAttrib(ObjectTag inp, Attribute attribute) {
if (inp == null) {
Debug.echoError("Tag parse failed (null return) for tag <" + attribute.toString() + ">!");
Debug.echoError("Tag parse failed (null return) for tag <LG><" + attribute.toString() + "<LG>><W>!");
return null;
}
if (attribute.isComplete()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Deprecations {

// In Bukkit impl, Added on 2018/12/23
// Bad candidate for functionality removal - a bit handy to use in "/ex", despite being clearly bad in standard scripts.
public static Warning playerByNameWarning = new SlowWarning("Warning: loading player by name - use the UUID instead (or use tag server.match_player)!");
public static Warning playerByNameWarning = new Warning("Warning: loading player by name - use the UUID instead (or use tag server.match_player)!");

// ==================== Tag shorthands ====================
// ====== All added on 2019/02/06 ======
Expand Down

0 comments on commit cfee015

Please sign in to comment.