{"record":{"id":"254b6aab1ba9e6d6","repo":"can1357/oh-my-pi","slug":"error-message-imageinputtoolargeerror-or-invalidi","errorCode":null,"errorMessage":"error.message (ImageInputTooLargeError or InvalidImageDataError)","messagePattern":"error\\.message \\(ImageInputTooLargeError or InvalidImageDataError\\)","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/read.ts","lineNumber":882,"sourceCode":"\t\t\t\tthrow new ToolError(\n\t\t\t\t\timageKind === \"svg\"\n\t\t\t\t\t\t? \"The ':img' selector only supports .svg and .svgz files.\"\n\t\t\t\t\t\t: `Read image file [${mimeType}] failed: unsupported image format.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{ type: \"text\", text: imageInput.textNote },\n\t\t\t\t\t{ type: \"image\", data: imageInput.data, mimeType: imageInput.mimeType },\n\t\t\t\t],\n\t\t\t\tdetails: {},\n\t\t\t\tsourcePath: imageInput.resolvedPath,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\t// Both surface as an actionable tool error so the model can fix the input\n\t\t\t// instead of the corrupt/oversized payload entering the transcript.\n\t\t\tif (error instanceof ImageInputTooLargeError || error instanceof InvalidImageDataError) {\n\t\t\t\tthrow new ToolError(error.message);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Render multiple non-contiguous ranges of a local file. ACP bridge takes\n\t * priority when present (editor buffer is source of truth); otherwise ranges\n\t * are sliced out of `buffered` when the caller already materialized the file,\n\t * and streamed independently with their own line/byte budget when it did not.\n\t * Out-of-bounds ranges surface as inline notices rather than aborting the read.\n\t */\n\tasync #readLocalFileMultiRange(\n\t\tabsolutePath: string,\n\t\tranges: readonly LineRange[],\n\t\tfileSize: number,\n\t\tbuffered: BufferedFileText | undefined,\n\t\tparsed: ParsedSelector,","sourceCodeStart":864,"sourceCodeEnd":900,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/read.ts#L864-L900","documentation":"When loadImageInput/loadSvgImageInput throw ImageInputTooLargeError (image exceeds size or post-decode dimension limits even after auto-resize) or InvalidImageDataError (bytes are not a decodable image), #loadImageContent converts them into ToolError with the original actionable message so the model can fix its input instead of a corrupt/oversized payload entering the transcript. Other error types propagate unchanged.","triggerScenarios":"Image too large after autoResize attempts (autoResize: this.#autoResizeImages with maxBytes: MAX_IMAGE_SIZE); decode failure on corrupt bytes; WebP excluded for the active model (excludeWebP) and no fallback possible; invalid SVG markup.","commonSituations":"Giant panoramas that cannot be resized enough; truncated or partially-written files; text files renamed .png; model-incompatible formats (WebP to a vision model that rejects it).","solutions":["Read error.message — it states whether the issue is size or decodability.","Resize/re-encode the image below the byte and pixel limits, then re-read.","Verify the bytes decode (open in an image viewer) — replace corrupt files.","For WebP-excluded models, convert to PNG/JPEG first."],"exampleFix":"// before\nread('huge-panorama.png') // ImageInputTooLargeError even after auto-resize\n// after\n$ `magick huge-panorama.png -resize 2000x -quality 85 small.jpg`\nread('small.jpg')","handlingStrategy":"validation","validationCode":"// pre-check both size and decodability\nimport { statSync } from 'node:fs';\nimport { fileTypeFromBuffer } from 'file-type';\nif (statSync(p).size > MAX_IMAGE_SIZE) await shrink(p);\nconst ft = await fileTypeFromBuffer(await Bun.file(p).bytes());\nconst mime = ft?.mime;\nif (!mime?.startsWith('image/')) throw new Error(`${p} is not a decodable image (${mime})`);","typeGuard":"function isImagePayloadError(e: unknown): e is ToolError {\n  return e instanceof ToolError &&\n    /too large|invalid|unsupported|corrupt/i.test(e.message);\n}","tryCatchPattern":"try {\n  return await readTool.execute({ path: imgPath });\n} catch (e) {\n  if (isImagePayloadError(e)) {\n    const fixed = await reencodeImage(imgPath); // resize + re-encode to JPEG\n    return await readTool.execute({ path: fixed });\n  }\n  throw e;\n}","preventionTips":["Read error.message first: it distinguishes size limits from undecodable data.","Re-encode any suspect image to baseline JPEG/PNG below the size cap.","Confirm files open in a viewer before feeding them to the tool.","Convert WebP to PNG for models that exclude WebP input."],"tags":["image","validation","decoding","file-size"],"backgroundTag":"invalid-image-data","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}