Improved debugging

This commit is contained in:
bigguy345 committed 2025-07-06 23:57:20 +03:00
1 parent ffd331fbc5
commit 8d63134a72
4 files changed
+35 -41

No files matched your search

@@ -97,6 +97,13 @@ public class Action implements IAction {
return this;
}
protected void schedule(IActionQueue queue) {
queue.getQueue().add(this);
this.queue = queue;
this.isScheduled = true;
}
@Override
public boolean isScheduled() {
return isScheduled;
@@ -248,30 +255,27 @@ public class Action implements IAction {
return;
}
if (duration % updateEveryXTick == 0 && task != null) {
if (isThreaded)
actionThread.execute("task", this::executeTask);
else
executeTask();
}
if (duration % updateEveryXTick == 0 && task != null)
execute("task", this::executeTask);
if (maxCount > -1 && count >= maxCount)
markDone();
}
public void execute(String taskName, Runnable task) {
if (isThreaded)
actionThread.execute(taskName, task);
else
task.run();
}
protected void executeTask() {
try {
task.accept(this);
count++;
} catch (Throwable t) {
String err = "Task of " + this + " threw an exception:";
if (reportTo != null)
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
System.err.println(err);
t.printStackTrace();
logDebug("Task of " + this + " threw an exception:", t);
markDone();
}
}
@@ -286,6 +290,19 @@ public class Action implements IAction {
done = true;
}
public void logDebug(String err) {
logDebug(err, null);
}
public void logDebug(String err, Throwable t) {
if (reportTo != null)
reportTo.appendConsole(err + (t != null ? "\n" + ExceptionUtils.getStackTrace(t) : ""));
System.err.println(err);
if (t != null)
t.printStackTrace();
}
public String toString() {
return String.format("IAction '%s' [queue='%s', scheduled=%s, done=%s, paused=%s, updateEvery=%s, duration=%d/%d, count=%d/%d, threaded=%s]", name != null ? name : "unnamed", queue != null ? queue.getName() : "null", isScheduled, done, isPaused(), updateEveryXTick, duration, maxDuration, count, maxCount, isThreaded);
}