{"record":{"id":"a56ab5ea5904a67d","repo":"moeru-ai/airi","slug":"target-not-found-a56ab5","errorCode":"TARGET_NOT_FOUND","errorMessage":"Could not find a chest nearby","messagePattern":"Could not find a chest nearby","errorType":"exception","errorClass":"ActionError","httpStatus":null,"severity":"warning","filePath":"integrations/minecraft/src/skills/actions/inventory.ts","lineNumber":82,"sourceCode":"  if (discarded === 0) {\n    logger.log(`You do not have any ${itemName} to discard.`)\n    throw new ActionError('ITEM_NOT_FOUND', `You do not have any ${itemName} to discard`, { item: itemName })\n  }\n  logger.log(`Successfully discarded ${discarded} ${itemName}.`)\n}\n\n/**\n * Put an item in a chest.\n * @param mineflayer The mineflayer instance.\n * @param itemName The name of the item to put in the chest.\n * @param num The number of items to put in the chest. Default is -1 for all.\n * @throws {ActionError} When no chest is nearby or the item is not in inventory.\n */\nexport async function putInChest(mineflayer: Mineflayer, itemName: string, num = -1): Promise<void> {\n  const chest = getNearestBlock(mineflayer, 'chest', 32)\n  if (!chest) {\n    logger.log(`Could not find a chest nearby.`)\n    throw new ActionError('TARGET_NOT_FOUND', 'Could not find a chest nearby', { blockType: 'chest' })\n  }\n  const item = mineflayer.bot.inventory\n    .items()\n    .find(item => item.name.includes(itemName))\n  if (!item) {\n    logger.log(`You do not have any ${itemName} to put in the chest.`)\n    throw new ActionError('ITEM_NOT_FOUND', `You do not have any ${itemName} to put in the chest`, { item: itemName })\n  }\n  const toPut = num === -1 ? item.count : Math.min(num, item.count)\n  await goToPosition(mineflayer, chest.position.x, chest.position.y, chest.position.z)\n  const chestContainer = await mineflayer.bot.openContainer(chest)\n  await chestContainer.deposit(item.type, null, toPut)\n  await chestContainer.close()\n  logger.log(`Successfully put ${toPut} ${itemName} in the chest.`)\n}\n\n/**\n * Take an item from a chest.","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/moeru-ai/airi/blob/27111382b4a79a7e983289d6e983a06af185ed0f/integrations/minecraft/src/skills/actions/inventory.ts#L64-L100","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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'."],"exampleFix":"// before\nexport async function putInChest(mineflayer: Mineflayer, itemName: string, num = -1): Promise<void> {\n  const chest = getNearestBlock(mineflayer, 'chest', 32)\n  if (!chest) {\n    throw new ActionError('TARGET_NOT_FOUND', 'Could not find a chest nearby', { blockType: 'chest' })\n  }\n  // ...\n}\n\n// after — accept a maxDistance param and auto-place one if the bot owns a chest item\nexport async function putInChest(mineflayer: Mineflayer, itemName: string, num = -1, maxDistance = 32): Promise<void> {\n  let chest = getNearestBlock(mineflayer, 'chest', maxDistance)\n  if (!chest) {\n    if (getItemCount(mineflayer, 'chest') > 0) {\n      const pos = getNearestFreeSpace(mineflayer, 1, 4)\n      await placeBlock(mineflayer, 'chest', pos.x, pos.y, pos.z)\n      chest = getNearestBlock(mineflayer, 'chest', maxDistance)\n    }\n  }\n  if (!chest) {\n    throw new ActionError('TARGET_NOT_FOUND', 'Could not find a chest nearby', { blockType: 'chest', maxDistance })\n  }\n  // ...\n}","handlingStrategy":"validation","validationCode":"import { getNearestBlock } from '../world'\nimport { getItemCount } from './inventory'\n\nfunction chestNearby(mineflayer: Mineflayer, maxDistance = 32): boolean {\n  return getNearestBlock(mineflayer, 'chest', maxDistance) != null\n}\n\nasync function ensureChestAccessible(mineflayer: Mineflayer): Promise<void> {\n  if (chestNearby(mineflayer)) return\n  if (getItemCount(mineflayer, 'chest') > 0) {\n    const pos = getNearestFreeSpace(mineflayer, 1, 4)\n    await placeBlock(mineflayer, 'chest', pos.x, pos.y, pos.z)\n    return\n  }\n  await ensureChests(mineflayer, 1)\n  const pos = getNearestFreeSpace(mineflayer, 1, 4)\n  await placeBlock(mineflayer, 'chest', pos.x, pos.y, pos.z)\n}\n\nawait ensureChestAccessible(mineflayer)\nawait putInChest(mineflayer, itemName, num)","typeGuard":"import type { Block } from 'prismarine-block'\n\nfunction isChestBlock(block: Block | null): block is Block {\n  return !!block && block.name === 'chest'\n}\n\nconst block = getNearestBlock(mineflayer, 'chest', 32)\nif (isChestBlock(block)) {\n  await putInChest(mineflayer, itemName, num)\n}","tryCatchPattern":"import { ActionError } from '../../utils/errors'\n\ntry {\n  await putInChest(mineflayer, itemName, num)\n} catch (err) {\n  if (err instanceof ActionError && err.code === 'TARGET_NOT_FOUND' && err.message.includes('chest nearby')) {\n    // Place a chest at the bot's feet and retry once\n    await ensureChests(mineflayer, 1)\n    const pos = getNearestFreeSpace(mineflayer, 1, 4)\n    await placeBlock(mineflayer, 'chest', pos.x, pos.y, pos.z)\n    await putInChest(mineflayer, itemName, num)\n  } else {\n    throw err\n  }\n}","preventionTips":["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."],"tags":["minecraft","chest","target-not-found","world","navigation"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}