Skip to content

Commit 921822a

Browse files
committed
Add messages to more exceptions and improve some existing ones
1 parent 497fb74 commit 921822a

File tree

13 files changed

+39
-22
lines changed

13 files changed

+39
-22
lines changed

src/api/java/baritone/api/pathing/goals/GoalRunAway.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public GoalRunAway(double distance, BlockPos... from) {
4444

4545
public GoalRunAway(double distance, Integer maintainY, BlockPos... from) {
4646
if (from.length == 0) {
47-
throw new IllegalArgumentException();
47+
throw new IllegalArgumentException("Positions to run away from must not be empty");
4848
}
4949
this.from = from;
5050
this.distanceSq = (int) (distance * distance);

src/main/java/baritone/pathing/calc/AStarPathFinder.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,25 @@ protected Optional<IPath> calculate0(long primaryTimeout, long failureTimeout) {
122122
continue;
123123
}
124124
if (actionCost <= 0 || Double.isNaN(actionCost)) {
125-
throw new IllegalStateException(moves + " calculated implausible cost " + actionCost);
125+
throw new IllegalStateException(String.format(
126+
"%s from %s %s %s calculated implausible cost %s",
127+
moves, currentNode.x, currentNode.y, currentNode.z, actionCost));
126128
}
127129
// 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
128130
if (moves.dynamicXZ && !worldBorder.entirelyContains(res.x, res.z)) { // see issue #218
129131
continue;
130132
}
131133
if (!moves.dynamicXZ && (res.x != newX || res.z != newZ)) {
132-
throw new IllegalStateException(moves + " " + res.x + " " + newX + " " + res.z + " " + newZ);
134+
throw new IllegalStateException(String.format(
135+
"%s from %s %s %s ended at x z %s %s instead of %s %s",
136+
moves, currentNode.x, currentNode.y, currentNode.z,
137+
res.x, res.z, newX, newZ));
133138
}
134139
if (!moves.dynamicY && res.y != currentNode.y + moves.yOffset) {
135-
throw new IllegalStateException(moves + " " + res.y + " " + (currentNode.y + moves.yOffset));
140+
throw new IllegalStateException(String.format(
141+
"%s from %s %s %s ended at y %s instead of %s",
142+
moves, currentNode.x, currentNode.y, currentNode.z,
143+
res.y, (currentNode.y + moves.yOffset)));
136144
}
137145
long hashCode = BetterBlockPos.longHash(res.x, res.y, res.z);
138146
if (isFavoring) {

src/main/java/baritone/pathing/calc/Path.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public Goal getGoal() {
112112

113113
private boolean assembleMovements() {
114114
if (path.isEmpty() || !movements.isEmpty()) {
115-
throw new IllegalStateException();
115+
throw new IllegalStateException("Path must not be empty");
116116
}
117117
for (int i = 0; i < path.size() - 1; i++) {
118118
double cost = nodes.get(i + 1).cost - nodes.get(i).cost;
@@ -145,7 +145,7 @@ private Movement runBackwards(BetterBlockPos src, BetterBlockPos dest, double co
145145
@Override
146146
public IPath postProcess() {
147147
if (verified) {
148-
throw new IllegalStateException();
148+
throw new IllegalStateException("Path must not be verified twice");
149149
}
150150
verified = true;
151151
boolean failed = assembleMovements();
@@ -154,7 +154,7 @@ public IPath postProcess() {
154154
if (failed) { // at least one movement became impossible during calculation
155155
CutoffPath res = new CutoffPath(this, movements().size());
156156
if (res.movements().size() != movements.size()) {
157-
throw new IllegalStateException();
157+
throw new IllegalStateException("Path has wrong size after cutoff");
158158
}
159159
return res;
160160
}
@@ -166,7 +166,8 @@ public IPath postProcess() {
166166
@Override
167167
public List<IMovement> movements() {
168168
if (!verified) {
169-
throw new IllegalStateException();
169+
// edge case note: this is called during verification
170+
throw new IllegalStateException("Path not yet verified");
170171
}
171172
return Collections.unmodifiableList(movements);
172173
}

src/main/java/baritone/pathing/calc/PathNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public PathNode(int x, int y, int z, Goal goal) {
6868
this.cost = ActionCosts.COST_INF;
6969
this.estimatedCostToGoal = goal.heuristic(x, y, z);
7070
if (Double.isNaN(estimatedCostToGoal)) {
71-
throw new IllegalStateException(goal + " calculated implausible heuristic");
71+
throw new IllegalStateException(goal + " calculated implausible heuristic NaN at " + x + " " + y + " " + z);
7272
}
7373
this.heapPosition = -1;
7474
this.x = x;

src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public final boolean isEmpty() {
9292
@Override
9393
public final PathNode removeLowest() {
9494
if (size == 0) {
95-
throw new IllegalStateException();
95+
throw new IllegalStateException("Cannot remove from empty heap");
9696
}
9797
PathNode result = array[1];
9898
PathNode val = array[size];

src/main/java/baritone/pathing/movement/Moves.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ public void apply(CalculationContext context, int x, int y, int z, MutableMoveRe
347347

348348
public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) {
349349
if (dynamicXZ || dynamicY) {
350-
throw new UnsupportedOperationException();
350+
throw new UnsupportedOperationException("Movements with dynamic offset must override `apply`");
351351
}
352352
result.x = x + xOffset;
353353
result.y = y + yOffset;
@@ -356,6 +356,6 @@ public void apply(CalculationContext context, int x, int y, int z, MutableMoveRe
356356
}
357357

358358
public double cost(CalculationContext context, int x, int y, int z) {
359-
throw new UnsupportedOperationException();
359+
throw new UnsupportedOperationException("Movements must override `cost` or `apply`");
360360
}
361361
}

src/main/java/baritone/pathing/path/PathExecutor.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,9 @@ private boolean shouldSprintNextTick() {
455455
if (data != null) {
456456
BetterBlockPos fallDest = new BetterBlockPos(data.getB());
457457
if (!path.positions().contains(fallDest)) {
458-
throw new IllegalStateException();
458+
throw new IllegalStateException(String.format(
459+
"Fall override at %s %s %s returned illegal destination %s %s %s",
460+
current.getSrc(), fallDest));
459461
}
460462
if (ctx.playerFeet().equals(fallDest)) {
461463
pathPosition = path.positions().indexOf(fallDest);
@@ -603,7 +605,9 @@ public PathExecutor trySplice(PathExecutor next) {
603605
}
604606
return SplicedPath.trySplice(path, next.path, false).map(path -> {
605607
if (!path.getDest().equals(next.getPath().getDest())) {
606-
throw new IllegalStateException();
608+
throw new IllegalStateException(String.format(
609+
"Path has end %s instead of %s after splicing",
610+
path.getDest(), next.getPath().getDest()));
607611
}
608612
PathExecutor ret = new PathExecutor(behavior, path);
609613
ret.pathPosition = pathPosition;
@@ -619,7 +623,9 @@ private PathExecutor cutIfTooLong() {
619623
int cutoffAmt = Baritone.settings().pathHistoryCutoffAmount.value;
620624
CutoffPath newPath = new CutoffPath(path, cutoffAmt, path.length() - 1);
621625
if (!newPath.getDest().equals(path.getDest())) {
622-
throw new IllegalStateException();
626+
throw new IllegalStateException(String.format(
627+
"Path has end %s instead of %s after trimming its start",
628+
newPath.getDest(), path.getDest()));
623629
}
624630
logDebug("Discarding earliest segment movements, length cut from " + path.length() + " to " + newPath.length());
625631
PathExecutor ret = new PathExecutor(behavior, newPath);

src/main/java/baritone/pathing/path/SplicedPath.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static Optional<SplicedPath> trySplice(IPath first, IPath second, boolean
9292
}
9393
int positionInSecond = second.positions().indexOf(first.positions().get(firstPositionInSecond));
9494
if (!allowOverlapCutoff && positionInSecond != 0) {
95-
throw new IllegalStateException();
95+
throw new IllegalStateException("Paths to be spliced are overlapping incorrectly");
9696
}
9797
List<BetterBlockPos> positions = new ArrayList<>();
9898
List<IMovement> movements = new ArrayList<>();

src/main/java/baritone/process/BuilderProcess.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ private static Vec3[] aabbSideMultipliers(Direction side) {
442442
double z = side.getStepZ() == 0 ? 0.5 : (1 + side.getStepZ()) / 2D;
443443
return new Vec3[]{new Vec3(x, 0.25, z), new Vec3(x, 0.75, z)};
444444
default: // null
445-
throw new IllegalStateException();
445+
throw new IllegalStateException("Unexpected side " + side);
446446
}
447447
}
448448

src/main/java/baritone/process/CustomGoalProcess.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
114114
}
115115
return new PathingCommand(this.goal, PathingCommandType.SET_GOAL_AND_PATH);
116116
default:
117-
throw new IllegalStateException();
117+
throw new IllegalStateException("Unexpected state " + this.state);
118118
}
119119
}
120120

src/main/java/baritone/process/ExploreProcess.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ private Goal[] closestUncachedChunks(BlockPos center, IChunkFilter filter) {
118118
int dz = (mult * 2 - 1) * zval; // dz can be either -zval or zval
119119
int trueDist = Math.abs(dx) + Math.abs(dz);
120120
if (trueDist != dist) {
121-
throw new IllegalStateException();
121+
throw new IllegalStateException(String.format(
122+
"Offset %s %s has distance %s, expected %s",
123+
dx, dz, trueDist, dist));
122124
}
123125
switch (filter.isAlreadyExplored(chunkX + dx, chunkZ + dz)) {
124126
case UNKNOWN:

src/main/java/baritone/utils/BlockStateInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public BlockStateInterface(IPlayerContext ctx, boolean copyLoadedChunks) {
7070
}
7171
this.useTheRealWorld = !Baritone.settings().pathThroughCachedOnly.value;
7272
if (!ctx.minecraft().isSameThread()) {
73-
throw new IllegalStateException();
73+
throw new IllegalStateException("BlockStateInterface must be constructed on the main thread");
7474
}
7575
this.isPassableBlockPos = new BlockPos.MutableBlockPos();
7676
this.access = new BlockStateInterfaceAccessWrapper(this);

src/main/java/baritone/utils/PathingControlManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void cancelEverything() { // called by PathingBehavior on TickEvent Type
6868
for (IBaritoneProcess proc : processes) {
6969
proc.onLostControl();
7070
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
71-
throw new IllegalStateException(proc.displayName());
71+
throw new IllegalStateException(proc.displayName() + " stayed active after being cancelled");
7272
}
7373
}
7474
}
@@ -121,7 +121,7 @@ public void preTick() {
121121
}
122122
break;
123123
default:
124-
throw new IllegalStateException();
124+
throw new IllegalStateException("Unexpected command type " + command.commandType);
125125
}
126126
}
127127

0 commit comments

Comments
 (0)