From 921822acd757c94d15c0081bcadee3af5b027d6e Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Fri, 18 Apr 2025 00:53:44 +0200 Subject: [PATCH 1/3] Add messages to more exceptions and improve some existing ones --- .../baritone/api/pathing/goals/GoalRunAway.java | 2 +- .../baritone/pathing/calc/AStarPathFinder.java | 14 +++++++++++--- src/main/java/baritone/pathing/calc/Path.java | 9 +++++---- src/main/java/baritone/pathing/calc/PathNode.java | 2 +- .../pathing/calc/openset/BinaryHeapOpenSet.java | 2 +- src/main/java/baritone/pathing/movement/Moves.java | 4 ++-- .../java/baritone/pathing/path/PathExecutor.java | 12 +++++++++--- .../java/baritone/pathing/path/SplicedPath.java | 2 +- src/main/java/baritone/process/BuilderProcess.java | 2 +- .../java/baritone/process/CustomGoalProcess.java | 2 +- src/main/java/baritone/process/ExploreProcess.java | 4 +++- .../java/baritone/utils/BlockStateInterface.java | 2 +- .../java/baritone/utils/PathingControlManager.java | 4 ++-- 13 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/api/java/baritone/api/pathing/goals/GoalRunAway.java b/src/api/java/baritone/api/pathing/goals/GoalRunAway.java index 49b6f708d..1a1b6e50c 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalRunAway.java +++ b/src/api/java/baritone/api/pathing/goals/GoalRunAway.java @@ -44,7 +44,7 @@ public class GoalRunAway implements Goal { public GoalRunAway(double distance, Integer maintainY, BlockPos... from) { if (from.length == 0) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Positions to run away from must not be empty"); } this.from = from; this.distanceSq = (int) (distance * distance); diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 0537eac5f..b22456584 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -122,17 +122,25 @@ public final class AStarPathFinder extends AbstractNodeCostSearch { continue; } if (actionCost <= 0 || Double.isNaN(actionCost)) { - throw new IllegalStateException(moves + " calculated implausible cost " + actionCost); + throw new IllegalStateException(String.format( + "%s from %s %s %s calculated implausible cost %s", + moves, currentNode.x, currentNode.y, currentNode.z, actionCost)); } // check destination after verifying it's not COST_INF -- some movements return a static IMPOSSIBLE object with COST_INF and destination being 0,0,0 to avoid allocating a new result for every failed calculation if (moves.dynamicXZ && !worldBorder.entirelyContains(res.x, res.z)) { // see issue #218 continue; } if (!moves.dynamicXZ && (res.x != newX || res.z != newZ)) { - throw new IllegalStateException(moves + " " + res.x + " " + newX + " " + res.z + " " + newZ); + throw new IllegalStateException(String.format( + "%s from %s %s %s ended at x z %s %s instead of %s %s", + moves, currentNode.x, currentNode.y, currentNode.z, + res.x, res.z, newX, newZ)); } if (!moves.dynamicY && res.y != currentNode.y + moves.yOffset) { - throw new IllegalStateException(moves + " " + res.y + " " + (currentNode.y + moves.yOffset)); + throw new IllegalStateException(String.format( + "%s from %s %s %s ended at y %s instead of %s", + moves, currentNode.x, currentNode.y, currentNode.z, + res.y, (currentNode.y + moves.yOffset))); } long hashCode = BetterBlockPos.longHash(res.x, res.y, res.z); if (isFavoring) { diff --git a/src/main/java/baritone/pathing/calc/Path.java b/src/main/java/baritone/pathing/calc/Path.java index 8f5dd52c2..eba408058 100644 --- a/src/main/java/baritone/pathing/calc/Path.java +++ b/src/main/java/baritone/pathing/calc/Path.java @@ -112,7 +112,7 @@ class Path extends PathBase { private boolean assembleMovements() { if (path.isEmpty() || !movements.isEmpty()) { - throw new IllegalStateException(); + throw new IllegalStateException("Path must not be empty"); } for (int i = 0; i < path.size() - 1; i++) { double cost = nodes.get(i + 1).cost - nodes.get(i).cost; @@ -145,7 +145,7 @@ class Path extends PathBase { @Override public IPath postProcess() { if (verified) { - throw new IllegalStateException(); + throw new IllegalStateException("Path must not be verified twice"); } verified = true; boolean failed = assembleMovements(); @@ -154,7 +154,7 @@ class Path extends PathBase { if (failed) { // at least one movement became impossible during calculation CutoffPath res = new CutoffPath(this, movements().size()); if (res.movements().size() != movements.size()) { - throw new IllegalStateException(); + throw new IllegalStateException("Path has wrong size after cutoff"); } return res; } @@ -166,7 +166,8 @@ class Path extends PathBase { @Override public List movements() { if (!verified) { - throw new IllegalStateException(); + // edge case note: this is called during verification + throw new IllegalStateException("Path not yet verified"); } return Collections.unmodifiableList(movements); } diff --git a/src/main/java/baritone/pathing/calc/PathNode.java b/src/main/java/baritone/pathing/calc/PathNode.java index 2b693338a..7db8f3f17 100644 --- a/src/main/java/baritone/pathing/calc/PathNode.java +++ b/src/main/java/baritone/pathing/calc/PathNode.java @@ -68,7 +68,7 @@ public final class PathNode { this.cost = ActionCosts.COST_INF; this.estimatedCostToGoal = goal.heuristic(x, y, z); if (Double.isNaN(estimatedCostToGoal)) { - throw new IllegalStateException(goal + " calculated implausible heuristic"); + throw new IllegalStateException(goal + " calculated implausible heuristic NaN at " + x + " " + y + " " + z); } this.heapPosition = -1; this.x = x; diff --git a/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java b/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java index 33f077b9d..1da8ed7e5 100644 --- a/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java +++ b/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java @@ -92,7 +92,7 @@ public final class BinaryHeapOpenSet implements IOpenSet { @Override public final PathNode removeLowest() { if (size == 0) { - throw new IllegalStateException(); + throw new IllegalStateException("Cannot remove from empty heap"); } PathNode result = array[1]; PathNode val = array[size]; diff --git a/src/main/java/baritone/pathing/movement/Moves.java b/src/main/java/baritone/pathing/movement/Moves.java index 87b5db6ac..312c8957c 100644 --- a/src/main/java/baritone/pathing/movement/Moves.java +++ b/src/main/java/baritone/pathing/movement/Moves.java @@ -347,7 +347,7 @@ public enum Moves { public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { if (dynamicXZ || dynamicY) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("Movements with dynamic offset must override `apply`"); } result.x = x + xOffset; result.y = y + yOffset; @@ -356,6 +356,6 @@ public enum Moves { } public double cost(CalculationContext context, int x, int y, int z) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("Movements must override `cost` or `apply`"); } } diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 5c89da116..96d105208 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -455,7 +455,9 @@ public class PathExecutor implements IPathExecutor, Helper { if (data != null) { BetterBlockPos fallDest = new BetterBlockPos(data.getB()); if (!path.positions().contains(fallDest)) { - throw new IllegalStateException(); + throw new IllegalStateException(String.format( + "Fall override at %s %s %s returned illegal destination %s %s %s", + current.getSrc(), fallDest)); } if (ctx.playerFeet().equals(fallDest)) { pathPosition = path.positions().indexOf(fallDest); @@ -603,7 +605,9 @@ public class PathExecutor implements IPathExecutor, Helper { } return SplicedPath.trySplice(path, next.path, false).map(path -> { if (!path.getDest().equals(next.getPath().getDest())) { - throw new IllegalStateException(); + throw new IllegalStateException(String.format( + "Path has end %s instead of %s after splicing", + path.getDest(), next.getPath().getDest())); } PathExecutor ret = new PathExecutor(behavior, path); ret.pathPosition = pathPosition; @@ -619,7 +623,9 @@ public class PathExecutor implements IPathExecutor, Helper { int cutoffAmt = Baritone.settings().pathHistoryCutoffAmount.value; CutoffPath newPath = new CutoffPath(path, cutoffAmt, path.length() - 1); if (!newPath.getDest().equals(path.getDest())) { - throw new IllegalStateException(); + throw new IllegalStateException(String.format( + "Path has end %s instead of %s after trimming its start", + newPath.getDest(), path.getDest())); } logDebug("Discarding earliest segment movements, length cut from " + path.length() + " to " + newPath.length()); PathExecutor ret = new PathExecutor(behavior, newPath); diff --git a/src/main/java/baritone/pathing/path/SplicedPath.java b/src/main/java/baritone/pathing/path/SplicedPath.java index 1ba497d81..7f083a662 100644 --- a/src/main/java/baritone/pathing/path/SplicedPath.java +++ b/src/main/java/baritone/pathing/path/SplicedPath.java @@ -92,7 +92,7 @@ public class SplicedPath extends PathBase { } int positionInSecond = second.positions().indexOf(first.positions().get(firstPositionInSecond)); if (!allowOverlapCutoff && positionInSecond != 0) { - throw new IllegalStateException(); + throw new IllegalStateException("Paths to be spliced are overlapping incorrectly"); } List positions = new ArrayList<>(); List movements = new ArrayList<>(); diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 5a93d12ec..753f33020 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -442,7 +442,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil double z = side.getStepZ() == 0 ? 0.5 : (1 + side.getStepZ()) / 2D; return new Vec3[]{new Vec3(x, 0.25, z), new Vec3(x, 0.75, z)}; default: // null - throw new IllegalStateException(); + throw new IllegalStateException("Unexpected side " + side); } } diff --git a/src/main/java/baritone/process/CustomGoalProcess.java b/src/main/java/baritone/process/CustomGoalProcess.java index d0dca9cbf..e101df74f 100644 --- a/src/main/java/baritone/process/CustomGoalProcess.java +++ b/src/main/java/baritone/process/CustomGoalProcess.java @@ -114,7 +114,7 @@ public final class CustomGoalProcess extends BaritoneProcessHelper implements IC } return new PathingCommand(this.goal, PathingCommandType.SET_GOAL_AND_PATH); default: - throw new IllegalStateException(); + throw new IllegalStateException("Unexpected state " + this.state); } } diff --git a/src/main/java/baritone/process/ExploreProcess.java b/src/main/java/baritone/process/ExploreProcess.java index 23fe7c23a..514a110e6 100644 --- a/src/main/java/baritone/process/ExploreProcess.java +++ b/src/main/java/baritone/process/ExploreProcess.java @@ -118,7 +118,9 @@ public final class ExploreProcess extends BaritoneProcessHelper implements IExpl int dz = (mult * 2 - 1) * zval; // dz can be either -zval or zval int trueDist = Math.abs(dx) + Math.abs(dz); if (trueDist != dist) { - throw new IllegalStateException(); + throw new IllegalStateException(String.format( + "Offset %s %s has distance %s, expected %s", + dx, dz, trueDist, dist)); } switch (filter.isAlreadyExplored(chunkX + dx, chunkZ + dz)) { case UNKNOWN: diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index 095694db9..19a0da57a 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -70,7 +70,7 @@ public class BlockStateInterface { } this.useTheRealWorld = !Baritone.settings().pathThroughCachedOnly.value; if (!ctx.minecraft().isSameThread()) { - throw new IllegalStateException(); + throw new IllegalStateException("BlockStateInterface must be constructed on the main thread"); } this.isPassableBlockPos = new BlockPos.MutableBlockPos(); this.access = new BlockStateInterfaceAccessWrapper(this); diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java index 3566cd23a..2205d62e7 100644 --- a/src/main/java/baritone/utils/PathingControlManager.java +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -68,7 +68,7 @@ public class PathingControlManager implements IPathingControlManager { for (IBaritoneProcess proc : processes) { proc.onLostControl(); if (proc.isActive() && !proc.isTemporary()) { // it's okay only for a temporary thing (like combat pause) to maintain control even if you say to cancel - throw new IllegalStateException(proc.displayName()); + throw new IllegalStateException(proc.displayName() + " stayed active after being cancelled"); } } } @@ -121,7 +121,7 @@ public class PathingControlManager implements IPathingControlManager { } break; default: - throw new IllegalStateException(); + throw new IllegalStateException("Unexpected command type " + command.commandType); } } From 7c4036dfb146a3ad566f0a3609c8c00a766d98b9 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Fri, 18 Apr 2025 23:28:39 +0200 Subject: [PATCH 2/3] Don't leak coordinates in exceptions --- .../pathing/calc/AStarPathFinder.java | 25 +++++++++++++++---- .../java/baritone/pathing/calc/PathNode.java | 8 +++++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index b22456584..41bc1ac0a 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -22,6 +22,7 @@ import baritone.api.pathing.calc.IPath; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.movement.ActionCosts; import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.SettingsUtil; import baritone.pathing.calc.openset.BinaryHeapOpenSet; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Moves; @@ -124,7 +125,11 @@ public final class AStarPathFinder extends AbstractNodeCostSearch { if (actionCost <= 0 || Double.isNaN(actionCost)) { throw new IllegalStateException(String.format( "%s from %s %s %s calculated implausible cost %s", - moves, currentNode.x, currentNode.y, currentNode.z, actionCost)); + moves, + SettingsUtil.maybeCensor(currentNode.x), + SettingsUtil.maybeCensor(currentNode.y), + SettingsUtil.maybeCensor(currentNode.z), + actionCost)); } // check destination after verifying it's not COST_INF -- some movements return a static IMPOSSIBLE object with COST_INF and destination being 0,0,0 to avoid allocating a new result for every failed calculation if (moves.dynamicXZ && !worldBorder.entirelyContains(res.x, res.z)) { // see issue #218 @@ -133,14 +138,24 @@ public final class AStarPathFinder extends AbstractNodeCostSearch { if (!moves.dynamicXZ && (res.x != newX || res.z != newZ)) { throw new IllegalStateException(String.format( "%s from %s %s %s ended at x z %s %s instead of %s %s", - moves, currentNode.x, currentNode.y, currentNode.z, - res.x, res.z, newX, newZ)); + moves, + SettingsUtil.maybeCensor(currentNode.x), + SettingsUtil.maybeCensor(currentNode.y), + SettingsUtil.maybeCensor(currentNode.z), + SettingsUtil.maybeCensor(res.x), + SettingsUtil.maybeCensor(res.z), + SettingsUtil.maybeCensor(newX), + SettingsUtil.maybeCensor(newZ))); } if (!moves.dynamicY && res.y != currentNode.y + moves.yOffset) { throw new IllegalStateException(String.format( "%s from %s %s %s ended at y %s instead of %s", - moves, currentNode.x, currentNode.y, currentNode.z, - res.y, (currentNode.y + moves.yOffset))); + moves, + SettingsUtil.maybeCensor(currentNode.x), + SettingsUtil.maybeCensor(currentNode.y), + SettingsUtil.maybeCensor(currentNode.z), + SettingsUtil.maybeCensor(res.y), + SettingsUtil.maybeCensor(currentNode.y + moves.yOffset))); } long hashCode = BetterBlockPos.longHash(res.x, res.y, res.z); if (isFavoring) { diff --git a/src/main/java/baritone/pathing/calc/PathNode.java b/src/main/java/baritone/pathing/calc/PathNode.java index 7db8f3f17..0911c6c04 100644 --- a/src/main/java/baritone/pathing/calc/PathNode.java +++ b/src/main/java/baritone/pathing/calc/PathNode.java @@ -20,6 +20,7 @@ package baritone.pathing.calc; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.movement.ActionCosts; import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.SettingsUtil; /** * A node in the path, containing the cost and steps to get to it. @@ -68,7 +69,12 @@ public final class PathNode { this.cost = ActionCosts.COST_INF; this.estimatedCostToGoal = goal.heuristic(x, y, z); if (Double.isNaN(estimatedCostToGoal)) { - throw new IllegalStateException(goal + " calculated implausible heuristic NaN at " + x + " " + y + " " + z); + throw new IllegalStateException(String.format( + "%s calculated implausible heuristic NaN at %s %s %s", + goal, + SettingsUtil.maybeCensor(x), + SettingsUtil.maybeCensor(y), + SettingsUtil.maybeCensor(z))); } this.heapPosition = -1; this.x = x; From 9e1e89b91fa5d402a92fd0db3d936e54e9380878 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Fri, 18 Apr 2025 23:34:16 +0200 Subject: [PATCH 3/3] Fix ancient comment --- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 41bc1ac0a..1c58cbf20 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -131,7 +131,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch { SettingsUtil.maybeCensor(currentNode.z), actionCost)); } - // check destination after verifying it's not COST_INF -- some movements return a static IMPOSSIBLE object with COST_INF and destination being 0,0,0 to avoid allocating a new result for every failed calculation + // check destination after verifying it's not COST_INF -- some movements return COST_INF without adjusting the destination if (moves.dynamicXZ && !worldBorder.entirelyContains(res.x, res.z)) { // see issue #218 continue; }