{"record":{"id":"dbf1b7adc77e2995","repo":"musistudio/claude-code-router","slug":"export-failed-to-resize-exported-png-fallback","errorCode":null,"errorMessage":"[export] Failed to resize exported PNG fallback: ${formatError(error)}","messagePattern":"\\[export\\] Failed to resize exported PNG fallback: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/electron/src/main/ipc.ts","lineNumber":730,"sourceCode":"    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();\n  } catch (error) {\n    console.warn(`[export] Failed to resize exported PNG fallback: ${formatError(error)}`);\n    return undefined;\n  }\n}\n\nfunction sanitizePngOutputDimension(value: unknown): number | undefined {\n  if (typeof value !== \"number\" || !Number.isFinite(value)) {\n    return undefined;\n  }\n  const rounded = Math.round(value);\n  return rounded > 0 && rounded <= 4096 ? rounded : undefined;\n}\n\nfunction decodePngPixels(png: Buffer): DecodedPngPixels {\n  if (png.length < 33 || !png.subarray(0, pngSignature.length).equals(pngSignature)) {\n    throw new Error(\"Invalid PNG file.\");\n  }\n\n  let offset = pngSignature.length;","sourceCodeStart":712,"sourceCodeEnd":748,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/electron/src/main/ipc.ts#L712-L748","documentation":"The fallback path (nativeImage.createFromBuffer + resize) also failed while resizing an exported PNG; the function returns undefined and the caller must handle a missing resized image.","triggerScenarios":"resizePngWithNativeImage receives an empty/invalid PNG buffer so createFromBuffer yields an empty image, or resize throws on non-positive dimensions.","commonSituations":"Chained after error 583 — original PNG was already corrupt; or height/width of 0 passed through.","solutions":["Check image.isEmpty() before resize (already done) and log the input buffer size to confirm corruption upstream","Guard height/width > 0 at the call site","Regenerate the source capture instead of relying on the resize fallback"],"exampleFix":"// before\nreturn image.resize({ height, width }).toPNG();\n// after\nif (height <= 0 || width <= 0) return undefined;\nreturn image.resize({ height: Math.round(height), width: Math.round(width) }).toPNG();","handlingStrategy":"fallback","validationCode":"if (!png || png.length < 8) return undefined;","typeGuard":"const isPngBuffer = (b: Buffer): boolean => b.length > 8 && b.subarray(1,4).toString('hex') === '504e47';","tryCatchPattern":"catch (error) { warn; return undefined; }","preventionTips":["Validate buffer signature before createFromBuffer","Clamp resize dims to positive integers"],"tags":["export","png","resize","native-image"],"backgroundTag":"image-resize-failed","analyzedSha":"99f24806c6a2c660b16e53e95211c517448a6c90","analyzedAt":"2026-08-27T04:11:01.184Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}