moeru-ai/airi · warning · ActionError
TARGET_NOT_FOUND
TARGET_NOT_FOUND
Error message
Could not find a chest nearby
What it means
Thrown by putInChest (and identically by takeFromChest, viewChest, transferAllToChest) when getNearestBlock(mineflayer, 'chest', 32) returns null — no chest block exists within the 32-block search radius around the bot.
Source
Thrown at integrations/minecraft/src/skills/actions/inventory.ts:82
if (discarded === 0) {
logger.log(`You do not have any ${itemName} to discard.`)
throw new ActionError('ITEM_NOT_FOUND', `You do not have any ${itemName} to discard`, { item: itemName })
}
logger.log(`Successfully discarded ${discarded} ${itemName}.`)
}
/**
* Put an item in a chest.
* @param mineflayer The mineflayer instance.
* @param itemName The name of the item to put in the chest.
* @param num The number of items to put in the chest. Default is -1 for all.
* @throws {ActionError} When no chest is nearby or the item is not in inventory.
*/
export async function putInChest(mineflayer: Mineflayer, itemName: string, num = -1): Promise<void> {
const chest = getNearestBlock(mineflayer, 'chest', 32)
if (!chest) {
logger.log(`Could not find a chest nearby.`)
throw new ActionError('TARGET_NOT_FOUND', 'Could not find a chest nearby', { blockType: 'chest' })
}
const item = mineflayer.bot.inventory
.items()
.find(item => item.name.includes(itemName))
if (!item) {
logger.log(`You do not have any ${itemName} to put in the chest.`)
throw new ActionError('ITEM_NOT_FOUND', `You do not have any ${itemName} to put in the chest`, { item: itemName })
}
const toPut = num === -1 ? item.count : Math.min(num, item.count)
await goToPosition(mineflayer, chest.position.x, chest.position.y, chest.position.z)
const chestContainer = await mineflayer.bot.openContainer(chest)
await chestContainer.deposit(item.type, null, toPut)
await chestContainer.close()
logger.log(`Successfully put ${toPut} ${itemName} in the chest.`)
}
/**
* Take an item from a chest.View on GitHub (pinned to 27111382b4)
Solutions
- Place a chest near the bot first: call ensureChests(mineflayer, 1) then placeBlock(mineflayer, 'chest', x, y, z) at the bot's feet.
- Move the bot within 32 blocks of a known chest location (path to base coordinates) before invoking putInChest.
- Increase the search radius (currently 32) if you control a fork of the call; otherwise relocate.
- Verify the chest block is in a loaded chunk: call mineflayer.bot.blockAt(position) and confirm it is non-null and named 'chest'.
Example fix
// before
export async function putInChest(mineflayer: Mineflayer, itemName: string, num = -1): Promise<void> {
const chest = getNearestBlock(mineflayer, 'chest', 32)
if (!chest) {
throw new ActionError('TARGET_NOT_FOUND', 'Could not find a chest nearby', { blockType: 'chest' })
}
// ...
}
// after — accept a maxDistance param and auto-place one if the bot owns a chest item
export async function putInChest(mineflayer: Mineflayer, itemName: string, num = -1, maxDistance = 32): Promise<void> {
let chest = getNearestBlock(mineflayer, 'chest', maxDistance)
if (!chest) {
if (getItemCount(mineflayer, 'chest') > 0) {
const pos = getNearestFreeSpace(mineflayer, 1, 4)
await placeBlock(mineflayer, 'chest', pos.x, pos.y, pos.z)
chest = getNearestBlock(mineflayer, 'chest', maxDistance)
}
}
if (!chest) {
throw new ActionError('TARGET_NOT_FOUND', 'Could not find a chest nearby', { blockType: 'chest', maxDistance })
}
// ...
} Defensive patterns
Strategy: validation
Validate before calling
import { getNearestBlock } from '../world'
import { getItemCount } from './inventory'
function chestNearby(mineflayer: Mineflayer, maxDistance = 32): boolean {
return getNearestBlock(mineflayer, 'chest', maxDistance) != null
}
async function ensureChestAccessible(mineflayer: Mineflayer): Promise<void> {
if (chestNearby(mineflayer)) return
if (getItemCount(mineflayer, 'chest') > 0) {
const pos = getNearestFreeSpace(mineflayer, 1, 4)
await placeBlock(mineflayer, 'chest', pos.x, pos.y, pos.z)
return
}
await ensureChests(mineflayer, 1)
const pos = getNearestFreeSpace(mineflayer, 1, 4)
await placeBlock(mineflayer, 'chest', pos.x, pos.y, pos.z)
}
await ensureChestAccessible(mineflayer)
await putInChest(mineflayer, itemName, num) Type guard
import type { Block } from 'prismarine-block'
function isChestBlock(block: Block | null): block is Block {
return !!block && block.name === 'chest'
}
const block = getNearestBlock(mineflayer, 'chest', 32)
if (isChestBlock(block)) {
await putInChest(mineflayer, itemName, num)
} Try / catch
import { ActionError } from '../../utils/errors'
try {
await putInChest(mineflayer, itemName, num)
} catch (err) {
if (err instanceof ActionError && err.code === 'TARGET_NOT_FOUND' && err.message.includes('chest nearby')) {
// Place a chest at the bot's feet and retry once
await ensureChests(mineflayer, 1)
const pos = getNearestFreeSpace(mineflayer, 1, 4)
await placeBlock(mineflayer, 'chest', pos.x, pos.y, pos.z)
await putInChest(mineflayer, itemName, num)
} else {
throw err
}
} Prevention
- Always ensure a chest is within 32 blocks before putInChest/takeFromChest/viewChest/transferAllToChest — the search radius is hardcoded.
- Place a chest at the bot's feet via placeBlock('chest', ...) before any chest operation in remote areas.
- For remote workflows, call ensureChests(mineflayer, 1) up front so a chest item is in inventory ready to place.
- Verify the chest chunk is loaded with mineflayer.bot.blockAt(position) before relying on getNearestBlock.
When it happens
Trigger: The bot is more than 32 blocks from any placed chest. A chest exists but is unloaded (chunk not sent by server). The chest block was destroyed or picked up. getNearestBlock walks loaded chunks only; if the bot is in a remote area with no chest placed, the lookup returns null and the throw fires immediately.
Common situations: Bot wandered away from base where chests live. No chest has been crafted/placed yet. Chest exists in a neighboring chunk that has not been loaded by player proximity. World-edit or griefing removed the chest. Server view-distance setting smaller than 32 chunks.
Related errors
- TARGET_NOT_FOUND
- NAVIGATION_FAILED
- Could not find any ${blockType} in ${range} blocks.
- Failed to reach ${blockType}: ${result.reason} — ${result.me
- Unknown action: ${step.tool}
AI-assisted analysis of moeru-ai/airi@27111382b4 (2026-08-12).
Data as JSON: /api/errors/a56ab5ea5904a67d.
Report an issue: GitHub.