{"record":{"id":"bbeb196c80c75492","repo":"can1357/oh-my-pi","slug":"could-not-rasterize-svg-message","errorCode":null,"errorMessage":"Could not rasterize SVG: ${message}","messagePattern":"Could not rasterize SVG: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/utils/image-loading.ts","lineNumber":497,"sourceCode":"\tif (extension !== \".svg\" && extension !== \".svgz\") return null;\n\n\tconst maxBytes = options.maxBytes ?? MAX_IMAGE_INPUT_BYTES;\n\tconst stat = await Bun.file(resolvedPath).stat();\n\tif (stat.size > maxBytes) {\n\t\tthrow new ImageInputTooLargeError(stat.size, maxBytes);\n\t}\n\n\tconst source = await fs.readFile(resolvedPath);\n\tif (source.byteLength > maxBytes) {\n\t\tthrow new ImageInputTooLargeError(source.byteLength, maxBytes);\n\t}\n\n\tlet png: Uint8Array;\n\ttry {\n\t\tpng = await rasterizeSvg(source, SVG_IMAGE_MAX_EDGE_PX, SVG_IMAGE_MAX_EDGE_PX);\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new Error(`Could not rasterize SVG: ${message}`);\n\t}\n\n\treturn loadInMemoryImageInput({\n\t\timage: {\n\t\t\ttype: \"image\",\n\t\t\tdata: Buffer.from(png.buffer, png.byteOffset, png.byteLength).toString(\"base64\"),\n\t\t\tmimeType: \"image/png\",\n\t\t},\n\t\tresolvedPath,\n\t\ttextNotePrefix: \"Read SVG file\",\n\t\tautoResize: options.autoResize,\n\t\tmaxBytes,\n\t\texcludeWebP: options.excludeWebP,\n\t});\n}\n\n/** Loads a chat attachment image through the same size and encoder policy as file-backed image inputs. */\nexport async function loadImageAttachmentInput(","sourceCodeStart":479,"sourceCodeEnd":515,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/utils/image-loading.ts#L479-L515","documentation":"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>'.","triggerScenarios":"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.","commonSituations":"SVGs exported with editor-specific features (Sketch/Figma filters), SVGs referencing external images or CSS, hand-written SVG with syntax errors, corrupted svgz payloads.","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."],"exampleFix":"// before: await loadImageInput(\"chart.svg\"); // uses <foreignObject>  // after: rsvg-convert -w 1568 chart.svg -o chart.png, then await loadImageInput(\"chart.png\");","handlingStrategy":"fallback","validationCode":"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\");","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["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."],"tags":["svg","rasterization","rendering"],"backgroundTag":"svg-rasterization-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}