refactor: streamline safety checks and error handling in mining operation for improved reliability

This commit is contained in:
MayaTheShy
2026-02-20 03:54:23 -05:00
parent 8fcd3f44c7
commit b8a1b7c0b3

View File

@@ -40,6 +40,7 @@ export class MiningState extends BaseState {
console.log(`[${this.turtle.id}] Starting mining operation`); console.log(`[${this.turtle.id}] Starting mining operation`);
while (!this.cancelled) { while (!this.cancelled) {
try {
// Safety checks // Safety checks
const fuel = await this.checkFuel(); const fuel = await this.checkFuel();
if (fuel !== 'unlimited' && fuel < this.minFuel) { if (fuel !== 'unlimited' && fuel < this.minFuel) {
@@ -82,6 +83,16 @@ export class MiningState extends BaseState {
// Explore step - try to find new areas // Explore step - try to find new areas
yield* this._exploreStep(); yield* this._exploreStep();
} catch (error) {
const isTimeout = error.message?.includes('timed out');
if (isTimeout) {
console.warn(`[${this.turtle.id}] Mining exec timeout, will retry next iteration`);
await this._sleep(3000);
} else {
throw error;
}
}
yield; yield;
await this._sleep(200); await this._sleep(200);
} }