{"record":{"id":"731af14aed6ef4dd","repo":"can1357/oh-my-pi","slug":"image-file-not-found-imagepath","errorCode":null,"errorMessage":"Image file not found: ${imagePath}","messagePattern":"Image file not found: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/image-gen.ts","lineNumber":798,"sourceCode":"}\n\nasync function loadImageFromPath(imagePath: string, cwd: string): Promise<InlineImageData> {\n\tconst resolved = resolveReadPath(imagePath, cwd);\n\ttry {\n\t\tconst buffer = await Bun.file(resolved).bytes();\n\t\tif (buffer.length > MAX_IMAGE_SIZE) {\n\t\t\tthrow new Error(`Image file too large: ${imagePath}`);\n\t\t}\n\n\t\tconst metadata = parseImageMetadata(buffer);\n\t\tconst mimeType = metadata?.mimeType;\n\t\tif (!mimeType) {\n\t\t\tthrow new Error(`Unsupported image type: ${imagePath}`);\n\t\t}\n\n\t\treturn { data: buffer.toBase64(), mimeType };\n\t} catch (err) {\n\t\tif (isEnoent(err)) throw new Error(`Image file not found: ${imagePath}`);\n\t\tthrow err;\n\t}\n}\n\nasync function resolveInputImage(input: ImageInput, cwd: string): Promise<InlineImageData> {\n\tif (input.path) {\n\t\treturn loadImageFromPath(input.path, cwd);\n\t}\n\n\tif (input.data) {\n\t\tconst normalized = normalizeDataUrl(input.data.trim());\n\t\tconst mimeType = normalized.mimeType ?? input.mime_type;\n\t\tif (!mimeType) {\n\t\t\tthrow new Error(\"mime_type is required when providing raw base64 data.\");\n\t\t}\n\t\tif (!normalized.data) {\n\t\t\tthrow new Error(\"Image data is empty.\");\n\t\t}","sourceCodeStart":780,"sourceCodeEnd":816,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/image-gen.ts#L780-L816","documentation":"When reading an input image from disk, an ENOENT (file does not exist) from Bun.file().bytes() is caught and rethrown as this friendlier error echoing the path as given. It distinguishes a missing input image from other read/parsing failures so users immediately see the path is wrong rather than getting a raw ENOENT stack.","triggerScenarios":"resolveInputImage is given a path that doesn't exist: typo'd filename, file outside the working dir with a relative path, deleted temp file, or wrong cwd assumption when resolving relative paths.","commonSituations":"Relative path resolved against a different cwd than expected; image generated into a temp dir that was cleaned up; case-sensitivity mismatch on case-sensitive filesystems; path containing unexpanded ~ or $VAR.","solutions":["Verify the path exists (`ls <path>` / `test -f <path>`) before calling the tool","Use an absolute path to avoid cwd ambiguity","Expand ~ and environment variables in the path before passing it","Check case sensitivity of the filename on Linux filesystems"],"exampleFix":"// before\n\"image\": \"~/Downloads/out.png\"  // ~ not expanded\n// after\n\"image\": \"/home/alice/Downloads/out.png\"","handlingStrategy":"validation","validationCode":"import { existsSync } from \"node:fs\";\nimport * as path from \"node:path\";\nfunction requireImagePath(p: string, cwd: string): string {\n\tconst abs = p.startsWith(\"~/\") ? path.join(process.env.HOME ?? \"\", p.slice(2)) : path.resolve(cwd, p);\n\tif (!existsSync(abs)) throw new Error(`Image file not found: ${abs}`);\n\treturn abs;\n}","typeGuard":null,"tryCatchPattern":"try {\n\tawait genImage({ image: imagePath });\n} catch (err) {\n\tif (err instanceof Error && err.message.startsWith(\"Image file not found:\")) {\n\t\tconsole.error(`Input image missing, resolved cwd=${process.cwd()}: ${imagePath}`);\n\t}\n\tthrow err;\n}","preventionTips":["Use absolute paths for input images to avoid cwd ambiguity","Check existence with fs.stat/Bun.file().exists() before the call","Expand ~ and $VARS in paths before invoking","Verify pipeline steps that generate the image completed before consuming it"],"tags":["file-not-found","enoent","path-resolution","image-generation"],"backgroundTag":"file-not-found","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}