can1357/oh-my-pi · error

Image file not found: ${imagePath}

Error message

Image file not found: ${imagePath}

What it means

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.

Source

Thrown at packages/coding-agent/src/tools/image-gen.ts:798

}

async function loadImageFromPath(imagePath: string, cwd: string): Promise<InlineImageData> {
	const resolved = resolveReadPath(imagePath, cwd);
	try {
		const buffer = await Bun.file(resolved).bytes();
		if (buffer.length > MAX_IMAGE_SIZE) {
			throw new Error(`Image file too large: ${imagePath}`);
		}

		const metadata = parseImageMetadata(buffer);
		const mimeType = metadata?.mimeType;
		if (!mimeType) {
			throw new Error(`Unsupported image type: ${imagePath}`);
		}

		return { data: buffer.toBase64(), mimeType };
	} catch (err) {
		if (isEnoent(err)) throw new Error(`Image file not found: ${imagePath}`);
		throw err;
	}
}

async function resolveInputImage(input: ImageInput, cwd: string): Promise<InlineImageData> {
	if (input.path) {
		return loadImageFromPath(input.path, cwd);
	}

	if (input.data) {
		const normalized = normalizeDataUrl(input.data.trim());
		const mimeType = normalized.mimeType ?? input.mime_type;
		if (!mimeType) {
			throw new Error("mime_type is required when providing raw base64 data.");
		}
		if (!normalized.data) {
			throw new Error("Image data is empty.");
		}

View on GitHub (pinned to 9690622007)

Solutions

  1. Verify the path exists (`ls <path>` / `test -f <path>`) before calling the tool
  2. Use an absolute path to avoid cwd ambiguity
  3. Expand ~ and environment variables in the path before passing it
  4. Check case sensitivity of the filename on Linux filesystems

Example fix

// before
"image": "~/Downloads/out.png"  // ~ not expanded
// after
"image": "/home/alice/Downloads/out.png"
Defensive patterns

Strategy: validation

Validate before calling

import { existsSync } from "node:fs";
import * as path from "node:path";
function requireImagePath(p: string, cwd: string): string {
	const abs = p.startsWith("~/") ? path.join(process.env.HOME ?? "", p.slice(2)) : path.resolve(cwd, p);
	if (!existsSync(abs)) throw new Error(`Image file not found: ${abs}`);
	return abs;
}

Try / catch

try {
	await genImage({ image: imagePath });
} catch (err) {
	if (err instanceof Error && err.message.startsWith("Image file not found:")) {
		console.error(`Input image missing, resolved cwd=${process.cwd()}: ${imagePath}`);
	}
	throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/731af14aed6ef4dd. Report an issue: GitHub.