{"record":{"id":"1abc6e8f0b98fb46","repo":"musistudio/claude-code-router","slug":"export-failed-to-process-exported-png-formate","errorCode":null,"errorMessage":"[export] Failed to process exported PNG: ${formatError(error)}","messagePattern":"\\[export\\] Failed to process exported PNG: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/electron/src/main/ipc.ts","lineNumber":710,"sourceCode":"  }\n\n  try {\n    const decoded = decodePngPixels(png);\n    let width = decoded.width;\n    let height = decoded.height;\n    let rgba = pngPixelsToRgba(decoded);\n    if (outputWidth && outputHeight && (outputWidth !== width || outputHeight !== height)) {\n      rgba = resizeRgbaBilinear(rgba, width, height, outputWidth, outputHeight);\n      width = outputWidth;\n      height = outputHeight;\n    }\n    if (radius > 0 && cssWidth > 0) {\n      const pixelRadius = Math.min(width / 2, height / 2, radius * width / cssWidth);\n      applyRoundedAlphaMask(rgba, width, height, pixelRadius);\n    }\n    return encodeRgbaPng(width, height, rgba);\n  } catch (error) {\n    console.warn(`[export] Failed to process exported PNG: ${formatError(error)}`);\n    const resized = resizePngWithNativeImage(png, outputWidth, outputHeight);\n    if (resized) {\n      return resized;\n    }\n    return png;\n  }\n}\n\nfunction resizePngWithNativeImage(png: Buffer, width?: number, height?: number): Buffer | undefined {\n  if (!width || !height) {\n    return undefined;\n  }\n  try {\n    const image = nativeImage.createFromBuffer(png);\n    if (image.isEmpty()) {\n      return undefined;\n    }\n    return image.resize({ height, width }).toPNG();","sourceCodeStart":692,"sourceCodeEnd":728,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/electron/src/main/ipc.ts#L692-L728","documentation":"Post-processing a captured PNG (decoding, resizing, or applying the rounded-corner alpha mask) failed, so the code falls back to native-image resizing or returns the raw PNG.","triggerScenarios":"captureElementPng/renderHtmlPng with extreme dimensions (0 or huge width/height), corrupt PNG bytes from capturePage, or a radius larger than the image producing invalid Math in the mask step.","commonSituations":"Capturing a hidden/zero-size element, outputWidth/outputHeight passed as 0 from unsanitized IPC input, or non-PNG bytes returned offscreen-render.","solutions":["Sanitize outputWidth/outputHeight with sanitizePngOutputDimension before calling","Ensure the captured element has non-zero size and is visible","Pass radius=0 to skip mask processing and test whether mask math is the cause"],"exampleFix":"// before\npngWithExportProcessing(png, { width, height, radius, cssWidth });\n// after\npngWithExportProcessing(png, {\n  width: sanitizePngOutputDimension(width) ?? png.width,\n  height: sanitizePngOutputDimension(height) ?? png.height,\n  radius, cssWidth\n});","handlingStrategy":"fallback","validationCode":"const w = sanitizePngOutputDimension(outputWidth); const h = sanitizePngOutputDimension(outputHeight); if (!w || !h || w * h > 50_000_000) throw new RangeError('bad dims');","typeGuard":"const isFinitePositive = (n: unknown): n is number => typeof n === 'number' && Number.isFinite(n) && n > 0;","tryCatchPattern":"catch (error) { warn; return resizePngWithNativeImage(png, w, h) ?? png; }","preventionTips":["Sanitize IPC-supplied dimensions","Ensure captured element is visible and non-zero size"],"tags":["export","png","electron-capture"],"backgroundTag":"image-processing-failed","analyzedSha":"99f24806c6a2c660b16e53e95211c517448a6c90","analyzedAt":"2026-08-27T04:11:01.184Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}