Skip to content

Commit 2fc8490

Browse files
authored
Merge pull request cabaletta#4712 from ZacSharp/pr/1.19.4/misc/moreExceptionMessages
Add messages to more exceptions and improve some existing ones
2 parents ddc2820 + 9e1e89b commit 2fc8490

File tree

13 files changed

+61
-23
lines changed

13 files changed

+61
-23
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: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import baritone.api.pathing.goals.Goal;
2323
import baritone.api.pathing.movement.ActionCosts;
2424
import baritone.api.utils.BetterBlockPos;
25+
import baritone.api.utils.SettingsUtil;
2526
import baritone.pathing.calc.openset.BinaryHeapOpenSet;
2627
import baritone.pathing.movement.CalculationContext;
2728
import baritone.pathing.movement.Moves;
@@ -122,17 +123,39 @@ protected Optional<IPath> calculate0(long primaryTimeout, long failureTimeout) {
122123
continue;
123124
}
124125
if (actionCost <= 0 || Double.isNaN(actionCost)) {
125-
throw new IllegalStateException(moves + " calculated implausible cost " + actionCost);
126+
throw new IllegalStateException(String.format(
127+
"%s from %s %s %s calculated implausible cost %s",
128+
moves,
129+
SettingsUtil.maybeCensor(currentNode.x),
130+
SettingsUtil.maybeCensor(currentNode.y),
131+
SettingsUtil.maybeCensor(currentNode.z),
132+
actionCost));
126133
}
127-
// 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
134+
// check destination after verifying it's not COST_INF -- some movements return COST_INF without adjusting the destination
128135
if (moves.dynamicXZ && !worldBorder.entirelyContains(res.x, res.z)) { // see issue #218
129136
continue;
130137
}
131138
if (!moves.dynamicXZ && (res.x != newX || res.z != newZ)) {
132-
throw new IllegalStateException(moves + " " + res.x + " " + newX + " " + res.z + " " + newZ);
139+
throw new IllegalStateException(String.format(
140+
"%s from %s %s %s ended at x z %s %s instead of %s %s",
141+
moves,
142+
SettingsUtil.maybeCensor(currentNode.x),
143+
SettingsUtil.maybeCensor(currentNode.y),
144+
SettingsUtil.maybeCensor(currentNode.z),
145+
SettingsUtil.maybeCensor(res.x),
146+
SettingsUtil.maybeCensor(res.z),
147+
SettingsUtil.maybeCensor(newX),
148+
SettingsUtil.maybeCensor(newZ)));
133149
}
134150
if (!moves.dynamicY && res.y != currentNode.y + moves.yOffset) {
135-
throw new IllegalStateException(moves + " " + res.y + " " + (currentNode.y + moves.yOffset));
151+
throw new IllegalStateException(String.format(
152+
"%s from %s %s %s ended at y %s instead of %s",
153+
moves,
154+
SettingsUtil.maybeCensor(currentNode.x),
155+
SettingsUtil.maybeCensor(currentNode.y),
156+
SettingsUtil.maybeCensor(currentNode.z),
157+
SettingsUtil.maybeCensor(res.y),
158+
SettingsUtil.maybeCensor(currentNode.y + moves.yOffset)));
136159
}
137160
long hashCode = BetterBlockPos.longHash(res.x, res.y, res.z);
138161
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import baritone.api.pathing.goals.Goal;
2121
import baritone.api.pathing.movement.ActionCosts;
2222
import baritone.api.utils.BetterBlockPos;
23+
import baritone.api.utils.SettingsUtil;
2324

2425
/**
2526
* A node in the path, containing the cost and steps to get to it.
@@ -68,7 +69,12 @@ public PathNode(int x, int y, int z, Goal goal) {
6869
this.cost = ActionCosts.COST_INF;
6970
this.estimatedCostToGoal = goal.heuristic(x, y, z);
7071
if (Double.isNaN(estimatedCostToGoal)) {
71-
throw new IllegalStateException(goal + " calculated implausible heuristic");
72+
throw new IllegalStateException(String.format(
73+
"%s calculated implausible heuristic NaN at %s %s %s",
74+
goal,
75+
SettingsUtil.maybeCensor(x),
76+
SettingsUtil.maybeCensor(y),
77+
SettingsUtil.maybeCensor(z)));
7278
}
7379
this.heapPosition = -1;
7480
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)