Skip to content

Commit

Permalink
invalid commands: error at load time
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 26, 2021
1 parent 25c46bc commit f5f6ac5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
Expand Up @@ -75,8 +75,7 @@ public static List<ScriptEntry> buildScriptEntries(List<Object> contents, Script
if (Debug.showScriptBuilder) {
Debug.echoDebug(parent, "Adding '" + scriptEntry[0] + "' Args: " + Arrays.toString(args));
}
ScriptEntry newEntry = new ScriptEntry(scriptEntry[0], args, parent, inside);
newEntry.internal.lineNumber = lineNum;
ScriptEntry newEntry = new ScriptEntry(scriptEntry[0], args, parent, inside, lineNum);
newEntry.internal.originalLine = entry;
newEntry.entryData.transferDataFrom(data);
scriptCommands.add(newEntry);
Expand Down
Expand Up @@ -163,7 +163,7 @@ public List<Object> getInsideList() {
}

public ScriptEntry(String command, String[] arguments, ScriptContainer script) {
this(command, arguments, script, null);
this(command, arguments, script, null, 0);
}

public void crunchInto(InternalArgument argVal, String arg, TagContext refContext) {
Expand All @@ -182,11 +182,12 @@ public void crunchInto(InternalArgument argVal, String arg, TagContext refContex
argVal.aHArg.hasSpecialPrefix = argVal.prefix != null;
}

public ScriptEntry(String command, String[] arguments, ScriptContainer script, List<Object> insides) {
public ScriptEntry(String command, String[] arguments, ScriptContainer script, List<Object> insides, int lineNum) {
if (command == null) {
throw new RuntimeException("Command name cannot be null!");
}
internal = new ScriptEntryInternal();
internal.lineNumber = lineNum;
entryData = DenizenCore.getImplementation().getEmptyScriptEntryData();
internal.command = command.toUpperCase();
internal.insideList = insides;
Expand All @@ -207,13 +208,16 @@ else if (command.charAt(0) == '~') {
internal.waitfor = true;
}
else if (internal.actualCommand != null) {
Debug.echoError("The command '" + internal.command + "' cannot be waited for!");
Debug.echoError(this, "The command '" + internal.command + "' cannot be waited for!");
}
}
internal.actualCommand = DenizenCore.getCommandRegistry().get(internal.command);
if (internal.actualCommand != null && internal.actualCommand.forceHold) {
internal.waitfor = true;
}
if (internal.actualCommand == null) {
Debug.echoError(this, "Unknown command '" + internal.command + "'.");
}
}
else {
internal.actualCommand = null;
Expand Down Expand Up @@ -255,7 +259,7 @@ else if (internal.actualCommand != null) {
if (parg.endsWith("{")) {
after = "{";
parg = parg.substring(0, parg.length() - 1);
Debug.echoError("Command '" + command + "' in script '" + (script == null ? "(None)" : script.getName()) + "' has typo: brace written without space... like 'arg{' when it should be 'arg {'.");
Debug.echoError(this, "Command '" + command + "' in script '" + (script == null ? "(None)" : script.getName()) + "' has typo: brace written without space... like 'arg{' when it should be 'arg {'.");
}
Argument argObj = new Argument(arg);
if (argObj.hasPrefix()) {
Expand Down
@@ -1,6 +1,7 @@
package com.denizenscript.denizencore.utilities.debugging;

import com.denizenscript.denizencore.DenizenCore;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.queues.ScriptQueue;

public class Debug {
Expand Down Expand Up @@ -31,6 +32,21 @@ public static void echoError(String error) {
DenizenCore.getImplementation().debugError(error);
}

public static void echoError(ScriptEntry entry, String error) {
if (entry == null) {
DenizenCore.getImplementation().debugError(error);
}
else if (entry.getResidingQueue() == null) {
if (entry.getScript() != null) {
error = "<R>In script '<A>" + entry.getScript().getName() + "<R>' on line <A>" + entry.internal.lineNumber + "<W>: " + error;
}
DenizenCore.getImplementation().debugError(error);
}
else {
DenizenCore.getImplementation().debugError(entry.getResidingQueue(), error);
}
}

public static void echoError(ScriptQueue queue, String error) {
DenizenCore.getImplementation().debugError(queue, error);
}
Expand Down

0 comments on commit f5f6ac5

Please sign in to comment.