Skip to content

Commit

Permalink
debug format fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 13, 2022
1 parent 3c14045 commit 8f48cbb
Show file tree
Hide file tree
Showing 25 changed files with 96 additions and 110 deletions.
Expand Up @@ -53,12 +53,12 @@ public interface DenizenImplementation {
/**
* Output an error to console, specific to a script queue.
*/
void debugError(ScriptQueue queue, String addedContext, String error);
void debugError(ScriptEntry queue, String addedContext, String error);

/**
* Output an error to console, specific to a script queue.
*/
void debugError(ScriptQueue queue, Throwable error);
void debugError(ScriptEntry queue, Throwable error);

/**
* Output a command information report.
Expand Down
Expand Up @@ -106,7 +106,7 @@ public static List<BracedData> getBracedCommands(ScriptEntry scriptEntry, boolea
}
}
catch (Exception e) {
Debug.echoError(scriptEntry.getResidingQueue(), e);
Debug.echoError(scriptEntry, e);
}
return res;
}
Expand Down Expand Up @@ -199,14 +199,14 @@ else if (arg.equals("}")) {
bd.entry = scriptEntry;
bd.key = bracesName;
if (bracedSections.contains(bd)) {
Debug.echoError(scriptEntry.getResidingQueue(), "You may not have braced commands with the same arguments.");
Debug.echoError(scriptEntry, "You may not have braced commands with the same arguments.");
break;
}
ArrayList<ScriptEntry> bracesSection = new ArrayList<>();
for (ArrayList<String> command : commandList.values()) {
if (command.isEmpty()) {
if (Debug.verbose) {
Debug.echoError(scriptEntry.getResidingQueue(), "Empty command?");
Debug.echoError(scriptEntry, "Empty command?");
}
continue;
}
Expand Down Expand Up @@ -276,7 +276,7 @@ else if (bracesEntered == 0) {
// Continue building the current command
else {
if (waitingForDash) {
Debug.echoError(scriptEntry.getResidingQueue(), "Malformed braced section! Missing a - symbol!");
Debug.echoError(scriptEntry, "Malformed braced section! Missing a - symbol!");
break;
}
newCommand = false;
Expand Down
Expand Up @@ -23,7 +23,7 @@ public static void debugSingleExecution(ScriptEntry scriptEntry) {
}
output.append(scriptEntry.getCommandName());
if (scriptEntry.getOriginalArguments() == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "Original Arguments null for " + scriptEntry.getCommandName());
Debug.echoError(scriptEntry, "Original Arguments null for " + scriptEntry.getCommandName());
}
else {
for (String arg : scriptEntry.getOriginalArguments()) {
Expand Down Expand Up @@ -123,7 +123,7 @@ else if (arg.matchesPrefix("save")) {
}
catch (InvalidArgumentsException | InvalidArgumentsRuntimeException e) {
// Give usage hint if InvalidArgumentsException was called.
Debug.echoError(scriptEntry.getResidingQueue(), "Woah! Invalid arguments were specified!");
Debug.echoError(scriptEntry, "Woah! Invalid arguments were specified!");
if (e.getMessage() != null && e.getMessage().length() > 0) {
Debug.log("+> MESSAGE follows: " + "'" + e.getMessage() + "'");
}
Expand All @@ -135,8 +135,8 @@ else if (arg.matchesPrefix("save")) {
return false;
}
catch (Throwable e) {
Debug.echoError(scriptEntry.getResidingQueue(), "Woah! An exception has been called with this command!");
Debug.echoError(scriptEntry.getResidingQueue(), e);
Debug.echoError(scriptEntry, "Woah! An exception has been called with this command!");
Debug.echoError(scriptEntry, e);
Debug.log("(Attempted: " + scriptEntry + ")");
Debug.echoDebug(scriptEntry, Debug.DebugElement.Footer);
scriptEntry.setFinished(true);
Expand Down
Expand Up @@ -141,15 +141,15 @@ public void execute(ScriptEntry scriptEntry) {
Debug.echoApproval(debug.asString());
break;
case ERROR:
Debug.echoError(scriptEntry.getResidingQueue(), debug.asString());
Debug.echoError(scriptEntry, debug.asString());
break;
case REPORT:
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, name.asString(), debug.asString());
}
break;
case EXCEPTION:
Debug.echoError(scriptEntry.getResidingQueue(), new RuntimeException(debug.asString()));
Debug.echoError(scriptEntry, new RuntimeException(debug.asString()));
break;
case RECORD:
String form = CoreUtilities.toLowerCase(debug.asString());
Expand Down
Expand Up @@ -28,10 +28,10 @@ public void execute(ScriptEntry scriptEntry) {
AbstractCommand command = DenizenCore.commandRegistry.get(scriptEntry.internal.command);
if (scriptEntry.internal.brokenArgs) {
if (scriptEntry.getOriginalArguments().size() > command.maximumArguments) {
Debug.echoError(scriptEntry.getResidingQueue(), scriptEntry.toString() + " cannot be executed! Too many arguments - did you forget to use quotes?\nUsage: " + command.getUsageHint());
Debug.echoError(scriptEntry, scriptEntry.toString() + " cannot be executed! Too many arguments - did you forget to use quotes?\nUsage: " + command.getUsageHint());
}
else {
Debug.echoError(scriptEntry.getResidingQueue(), scriptEntry.toString() + " cannot be executed! Too few arguments - did you forget a required input?\nUsage: " + command.getUsageHint());
Debug.echoError(scriptEntry, scriptEntry.toString() + " cannot be executed! Too few arguments - did you forget a required input?\nUsage: " + command.getUsageHint());
}
return;
}
Expand All @@ -47,7 +47,7 @@ public void execute(ScriptEntry scriptEntry) {
scriptEntry.getResidingQueue().injectEntryAtStart(scriptEntry);
return;
}
Debug.echoError(scriptEntry.getResidingQueue(), scriptEntry.getCommandName() + " is an invalid command! Are you sure it loaded?");
Debug.echoError(scriptEntry, scriptEntry.getCommandName() + " is an invalid command! Are you sure it loaded?");
}
Debug.echoDebug(scriptEntry, Debug.DebugElement.Footer);
}
Expand Down
Expand Up @@ -265,7 +265,7 @@ public void execute(final ScriptEntry scriptEntry) {
return;
}
if (connections.containsKey(redisID)) {
Debug.echoError(scriptEntry.getResidingQueue(), "Already connected to a server with ID '" + redisID + "'!");
Debug.echoError(scriptEntry, "Already connected to a server with ID '" + redisID + "'!");
scriptEntry.setFinished(true);
return;
}
Expand All @@ -279,10 +279,10 @@ public void execute(final ScriptEntry scriptEntry) {
}
catch (final Exception e) {
DenizenCore.schedule(new OneTimeSchedulable(() -> {
Debug.echoError(scriptEntry.getResidingQueue(), "Redis Exception: " + e.getMessage());
Debug.echoError(scriptEntry, "Redis Exception: " + e.getMessage());
scriptEntry.setFinished(true);
if (Debug.verbose) {
Debug.echoError(scriptEntry.getResidingQueue(), e);
Debug.echoError(scriptEntry, e);
}
}, 0));
}
Expand All @@ -309,7 +309,7 @@ public void execute(final ScriptEntry scriptEntry) {
}
else if (action.asString().equalsIgnoreCase("disconnect")) {
if (!connections.containsKey(redisID)) {
Debug.echoError(scriptEntry.getResidingQueue(), "Not connected to redis server with ID '" + redisID + "'!");
Debug.echoError(scriptEntry, "Not connected to redis server with ID '" + redisID + "'!");
scriptEntry.setFinished(true);
return;
}
Expand All @@ -335,12 +335,12 @@ else if (action.asString().equalsIgnoreCase("disconnect")) {
else if (action.asString().equalsIgnoreCase("subscribe")) {
Jedis con = connections.get(redisID);
if (con == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "Not connected to redis server with ID '" + redisID + "'!");
Debug.echoError(scriptEntry, "Not connected to redis server with ID '" + redisID + "'!");
scriptEntry.setFinished(true);
return;
}
if (subscriptions.containsKey(redisID)) {
Debug.echoError(scriptEntry.getResidingQueue(), "Already subscribed to a channel on redis server with ID '" + redisID + "'!");
Debug.echoError(scriptEntry, "Already subscribed to a channel on redis server with ID '" + redisID + "'!");
scriptEntry.setFinished(true);
return;
}
Expand All @@ -355,12 +355,12 @@ else if (action.asString().equalsIgnoreCase("subscribe")) {
}
else if (action.asString().equalsIgnoreCase("unsubscribe")) {
if (!connections.containsKey(redisID)) {
Debug.echoError(scriptEntry.getResidingQueue(), "Not connected to redis server with ID '" + redisID + "'!");
Debug.echoError(scriptEntry, "Not connected to redis server with ID '" + redisID + "'!");
scriptEntry.setFinished(true);
return;
}
if (!subscriptions.containsKey(redisID)) {
Debug.echoError(scriptEntry.getResidingQueue(), "Not subscribed to redis server with ID '" + redisID + "'!");
Debug.echoError(scriptEntry, "Not subscribed to redis server with ID '" + redisID + "'!");
scriptEntry.setFinished(true);
return;
}
Expand All @@ -374,18 +374,18 @@ else if (action.asString().equalsIgnoreCase("unsubscribe")) {
}
else if (action.asString().equalsIgnoreCase("publish")) {
if (message == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "Must specify a valid message to publish!");
Debug.echoError(scriptEntry, "Must specify a valid message to publish!");
scriptEntry.setFinished(true);
return;
}
final Jedis con = connections.get(redisID);
if (con == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "Not connected to redis server with ID '" + redisID + "'!");
Debug.echoError(scriptEntry, "Not connected to redis server with ID '" + redisID + "'!");
scriptEntry.setFinished(true);
return;
}
if (subscriptions.containsKey(redisID)) {
Debug.echoError(scriptEntry.getResidingQueue(), "Cannot publish messages while subscribed to redis server with ID '" + redisID + "'!");
Debug.echoError(scriptEntry, "Cannot publish messages while subscribed to redis server with ID '" + redisID + "'!");
scriptEntry.setFinished(true);
return;
}
Expand All @@ -400,10 +400,10 @@ else if (action.asString().equalsIgnoreCase("publish")) {
}
catch (final Exception ex) {
DenizenCore.schedule(new OneTimeSchedulable(() -> {
Debug.echoError(scriptEntry.getResidingQueue(), "Redis Exception: " + ex.getMessage());
Debug.echoError(scriptEntry, "Redis Exception: " + ex.getMessage());
scriptEntry.setFinished(true);
if (Debug.verbose) {
Debug.echoError(scriptEntry.getResidingQueue(), ex);
Debug.echoError(scriptEntry, ex);
}
}, 0));
}
Expand All @@ -417,18 +417,18 @@ else if (action.asString().equalsIgnoreCase("publish")) {
}
else if (action.asString().equalsIgnoreCase("command")) {
if (command == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "Must specify a valid redis command!");
Debug.echoError(scriptEntry, "Must specify a valid redis command!");
scriptEntry.setFinished(true);
return;
}
final Jedis con = connections.get(redisID);
if (con == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "Not connected to redis server with ID '" + redisID + "'!");
Debug.echoError(scriptEntry, "Not connected to redis server with ID '" + redisID + "'!");
scriptEntry.setFinished(true);
return;
}
if (subscriptions.containsKey(redisID)) {
Debug.echoError(scriptEntry.getResidingQueue(), "Cannot run commands while subscribed to redis server with ID '" + redisID + "'!");
Debug.echoError(scriptEntry, "Cannot run commands while subscribed to redis server with ID '" + redisID + "'!");
scriptEntry.setFinished(true);
return;
}
Expand All @@ -454,10 +454,10 @@ else if (action.asString().equalsIgnoreCase("command")) {
}
catch (final Exception ex) {
DenizenCore.schedule(new OneTimeSchedulable(() -> {
Debug.echoError(scriptEntry.getResidingQueue(), "Redis Exception: " + ex.getMessage());
Debug.echoError(scriptEntry, "Redis Exception: " + ex.getMessage());
scriptEntry.setFinished(true);
if (Debug.verbose) {
Debug.echoError(scriptEntry.getResidingQueue(), ex);
Debug.echoError(scriptEntry, ex);
}
}, 0));
}
Expand All @@ -470,13 +470,13 @@ else if (action.asString().equalsIgnoreCase("command")) {
}
}
else {
Debug.echoError(scriptEntry.getResidingQueue(), "Unknown action '" + action.asString() + "'");
Debug.echoError(scriptEntry, "Unknown action '" + action.asString() + "'");
}
}
catch (Exception ex) {
Debug.echoError(scriptEntry.getResidingQueue(), "Redis Exception: " + ex.getMessage());
Debug.echoError(scriptEntry, "Redis Exception: " + ex.getMessage());
if (Debug.verbose) {
Debug.echoError(scriptEntry.getResidingQueue(), ex);
Debug.echoError(scriptEntry, ex);
}
}
}
Expand Down

0 comments on commit 8f48cbb

Please sign in to comment.