can1357/oh-my-pi · error

Unsupported image type: ${imagePath}

Error message

Unsupported image type: ${imagePath}

What it means

The tool parses magic bytes with parseImageMetadata to determine the image's mime type; if no known signature matches (PNG, JPEG, GIF, WebP, etc.), it throws this error naming the path. This catches files that are not real images — renamed text files, SVG/XML, HEIC, or truncated downloads — before they are base64'd and sent to a provider.

Source

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

		case "deepinfra":
			return findDeepInfraImageCredentials(modelRegistry, sessionId);
		case "gemini":
			return findGeminiImageCredentials(modelRegistry, sessionId);
	}
}

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) {

View on GitHub (pinned to 9690622007)

Solutions

  1. Convert the file to PNG/JPEG/WebP first (e.g. `magick logo.svg logo.png` or HEIC→JPEG)
  2. Verify the file opens in an image viewer — corruption or truncation means re-download
  3. Check the actual file type with `file <path>` to see what it really is
  4. Ensure the source isn't a text/XML file with an image extension

Example fix

// before
"image": "logo.svg"
// after (shell)
magick logo.svg -resize 1024x1024 logo.png
// tool call
"image": "logo.png"
Defensive patterns

Strategy: validation

Validate before calling

import { readFileSync } from "node:fs";
const SIGNATURES: Array<[number[], string]> = [
	[[0x89, 0x50, 0x4e, 0x47], "image/png"],
	[[0xff, 0xd8, 0xff], "image/jpeg"],
	[[0x47, 0x49, 0x46], "image/gif"],
];
function sniffImageType(path: string): string | null {
	const b = readFileSync(path).subarray(0, 4);
	for (const [sig, mime] of SIGNATURES) if (sig.every((v, i) => b[i] === v)) return mime;
	return null;
}

Type guard

function isPngOrJpeg(path: string): boolean {
	const b = readFileSync(path).subarray(0, 3);
	return (b[0] === 0x89 && b[1] === 0x50) || (b[0] === 0xff && b[1] === 0xd8);
}

Try / catch

try {
	await genImage({ image: path });
} catch (err) {
	if (err instanceof Error && err.message.startsWith("Unsupported image type:")) {
		// convert to PNG then retry, or surface to user
	}
	throw err;
}

Prevention

When it happens

Trigger: loadImageFromPath reads a file whose first bytes don't match any supported image signature: an .svg (text-based), a .heic/.heif (unsupported codec), a corrupted/truncated image, or a text file with an image extension.

Common situations: SVG logos passed directly; iPhone HEIC photos on non-supporting setups; partially downloaded images; files renamed from .txt to .png.

Related errors


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