moeru-ai/airi · warning · Error
Expectation failed: expectNear() requires target argument or
Error message
Expectation failed: expectNear() requires target argument or last action distanceToTargetAfter telemetry
What it means
globalThis.expectNear() with no target coordinate argument falls back to reading globalThis.lastAction.result.distanceToTargetAfter. If that telemetry number is also absent (no target supplied AND no fallback distance), the helper has nothing to compare against maxDist and throws. This is the no-argument / distance-only overload's precondition failure.
Source
Thrown at integrations/minecraft/src/cognitive/conscious/js-planner.ts:1293
let distance = null
if (target) {
const endPos = globalThis.lastAction?.result?.endPos
if (!endPos || typeof endPos.x !== 'number' || typeof endPos.y !== 'number' || typeof endPos.z !== 'number') {
throw new Error('Expectation failed: expectNear(target) requires last action result with endPos telemetry')
}
const dx = endPos.x - target.x
const dy = endPos.y - target.y
const dz = endPos.z - target.z
distance = Math.sqrt(dx * dx + dy * dy + dz * dz)
}
else if (typeof globalThis.lastAction?.result?.distanceToTargetAfter === 'number') {
distance = globalThis.lastAction.result.distanceToTargetAfter
}
if (distance === null) {
throw new Error('Expectation failed: expectNear() requires target argument or last action distanceToTargetAfter telemetry')
}
if (distance <= maxDist)
return true
throw new Error(
'Expectation failed: ' + __plannerExpectationDetail(message, 'Expected distance <= ' + maxDist + ', got ' + distance),
)
}
globalThis.use = (toolName, params = {}) => {
if (typeof toolName !== 'string' || toolName.length === 0)
throw new Error('use(toolName, params) requires a non-empty string toolName')
const invocationArgs = params && typeof params === 'object' && !Array.isArray(params) ? [params] : [{}]
const runtimeResult = __plannerCallBridge('tool', [toolName, invocationArgs])
globalThis.lastAction = runtimeResult
globalThis.lastRun.actions.push(runtimeResult)View on GitHub (pinned to 27111382b4)
Solutions
- Pass an explicit target {x,y,z} to expectNear so it does not depend on distanceToTargetAfter.
- Call a movement action that reports distanceToTargetAfter before the no-target expectNear.
- Log globalThis.lastAction.result to confirm which telemetry fields the action actually provides.
Example fix
// before
// expectNear(2) // throws: no target and no distanceToTargetAfter
//
// after
// expectNear({ x: 10, y: 64, z: -5 }, 2) Defensive patterns
Strategy: validation
Validate before calling
// Before the no-target expectNear, confirm fallback telemetry:
// if (typeof globalThis.lastAction?.result?.distanceToTargetAfter === 'number') {
// expectNear(maxDist)
// } else {
// expectNear(explicitTarget, maxDist) // pass a target instead
// } Type guard
function hasDistanceAfter(r: unknown): r is { distanceToTargetAfter: number } {
return !!r && typeof r === 'object' && typeof (r as any).distanceToTargetAfter === 'number'
} Prevention
- Pass an explicit target {x,y,z} when you cannot rely on distanceToTargetAfter.
- Confirm the preceding action actually reports distanceToTargetAfter.
- Log lastAction.result before the assertion to verify telemetry shape.
When it happens
Trigger: Calling expectNear() or expectNear(2) with no target object and the last action result lacks distanceToTargetAfter; calling expectNear before any action ran; the preceding action does not report distanceToTargetAfter (only some movement actions do).
Common situations: Expecting the helper to auto-target the last moveTo destination but the action did not populate distanceToTargetAfter; first call in a turn with globalThis.lastAction null; result schema change dropped the field.
Related errors
- Expectation failed: expectNear(target) requires last action
- Expectation failed: Expected distance <= ${maxDist}, got ${d
- Expectation failed: Condition evaluated to false
- Expectation failed: Expected movedDistance >= ${threshold},
- Your last reply was natural language, not JavaScript, so not
AI-assisted analysis of moeru-ai/airi@27111382b4 (2026-08-12).
Data as JSON: /api/errors/4a32cc289eef5421.
Report an issue: GitHub.