can1357/oh-my-pi · error
Could not rasterize SVG: ${message}
Error message
Could not rasterize SVG: ${message} What it means
loadSvgImageInput rasterizes SVG source bytes to PNG via rasterizeSvg at SVG_IMAGE_MAX_EDGE_PX; if rasterization throws (malformed SVG, unsupported features, renderer crash), the original error is rethrown as 'Could not rasterize SVG: <reason>'.
Source
Thrown at packages/coding-agent/src/utils/image-loading.ts:497
if (extension !== ".svg" && extension !== ".svgz") return null;
const maxBytes = options.maxBytes ?? MAX_IMAGE_INPUT_BYTES;
const stat = await Bun.file(resolvedPath).stat();
if (stat.size > maxBytes) {
throw new ImageInputTooLargeError(stat.size, maxBytes);
}
const source = await fs.readFile(resolvedPath);
if (source.byteLength > maxBytes) {
throw new ImageInputTooLargeError(source.byteLength, maxBytes);
}
let png: Uint8Array;
try {
png = await rasterizeSvg(source, SVG_IMAGE_MAX_EDGE_PX, SVG_IMAGE_MAX_EDGE_PX);
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
throw new Error(`Could not rasterize SVG: ${message}`);
}
return loadInMemoryImageInput({
image: {
type: "image",
data: Buffer.from(png.buffer, png.byteOffset, png.byteLength).toString("base64"),
mimeType: "image/png",
},
resolvedPath,
textNotePrefix: "Read SVG file",
autoResize: options.autoResize,
maxBytes,
excludeWebP: options.excludeWebP,
});
}
/** Loads a chat attachment image through the same size and encoder policy as file-backed image inputs. */
export async function loadImageAttachmentInput(View on GitHub (pinned to 9690622007)
Solutions
- Read the underlying reason after 'Could not rasterize SVG:' and fix the SVG feature it names (remove filters, foreignObject, external refs).
- Validate the XML with an SVG/XML linter and fix syntax errors.
- Flatten the design: re-export from the editor as plain paths with embedded fonts and no filters.
- Pre-convert the SVG to PNG with a full-featured renderer (rsvg-convert, Inkscape, resvg) and load the PNG instead.
Example fix
// before: await loadImageInput("chart.svg"); // uses <foreignObject> // after: rsvg-convert -w 1568 chart.svg -o chart.png, then await loadImageInput("chart.png"); Defensive patterns
Strategy: fallback
Validate before calling
const text = await Bun.file(svgPath).text(); if (text.includes("<foreignObject") || text.includes("<filter")) throw new Error("SVG uses unsupported rasterizer features"); if (!text.startsWith("<?xml") && !text.includes("<svg")) throw new Error("not well-formed SVG"); Try / catch
try { const img = await loadImageInput(svgPath); } catch (err) { if (err instanceof Error && err.message.startsWith("Could not rasterize SVG:")) { const pngPath = await rasterizeExternally(svgPath); return loadImageInput(pngPath); } throw err; } Prevention
- Keep a non-Bun rasterizer (resvg/rsvg-convert) as fallback for feature-rich SVGs.
- Lint SVGs for filters, foreignObject, and external references before loading.
- Re-export complex designs as plain-path SVGs or pre-rendered PNGs.
- Validate XML well-formedness at ingestion.
When it happens
Trigger: Calling the SVG loading path with SVG content the rasterizer cannot process: malformed XML, unsupported SVG features (filters, foreignObject, external refs), or a renderer failure.
Common situations: SVGs exported with editor-specific features (Sketch/Figma filters), SVGs referencing external images or CSS, hand-written SVG with syntax errors, corrupted svgz payloads.
Related errors
- VHS failed to render the gallery screenshot${detail ? `: ${d
- snapcompact cannot render this conversation locally: unsuppo
- imageKind === "svg" ? "The ':img' selector only supports .sv
- imageSelectorMessage = "The ':img' selector only supports lo
- Image file too large: ${formatBytes(source.byteLength)} exce
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/bbeb196c80c75492.
Report an issue: GitHub.