musistudio/claude-code-router · warning

[export] Failed to resize exported PNG fallback: ${formatErr

Error message

[export] Failed to resize exported PNG fallback: ${formatError(error)}

What it means

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.

Source

Thrown at packages/electron/src/main/ipc.ts:730

    if (resized) {
      return resized;
    }
    return png;
  }
}

function resizePngWithNativeImage(png: Buffer, width?: number, height?: number): Buffer | undefined {
  if (!width || !height) {
    return undefined;
  }
  try {
    const image = nativeImage.createFromBuffer(png);
    if (image.isEmpty()) {
      return undefined;
    }
    return image.resize({ height, width }).toPNG();
  } catch (error) {
    console.warn(`[export] Failed to resize exported PNG fallback: ${formatError(error)}`);
    return undefined;
  }
}

function sanitizePngOutputDimension(value: unknown): number | undefined {
  if (typeof value !== "number" || !Number.isFinite(value)) {
    return undefined;
  }
  const rounded = Math.round(value);
  return rounded > 0 && rounded <= 4096 ? rounded : undefined;
}

function decodePngPixels(png: Buffer): DecodedPngPixels {
  if (png.length < 33 || !png.subarray(0, pngSignature.length).equals(pngSignature)) {
    throw new Error("Invalid PNG file.");
  }

  let offset = pngSignature.length;

View on GitHub (pinned to 99f24806c6)

Solutions

  1. Check image.isEmpty() before resize (already done) and log the input buffer size to confirm corruption upstream
  2. Guard height/width > 0 at the call site
  3. Regenerate the source capture instead of relying on the resize fallback

Example fix

// before
return image.resize({ height, width }).toPNG();
// after
if (height <= 0 || width <= 0) return undefined;
return image.resize({ height: Math.round(height), width: Math.round(width) }).toPNG();
Defensive patterns

Strategy: fallback

Validate before calling

if (!png || png.length < 8) return undefined;

Type guard

const isPngBuffer = (b: Buffer): boolean => b.length > 8 && b.subarray(1,4).toString('hex') === '504e47';

Try / catch

catch (error) { warn; return undefined; }

Prevention

When it happens

Trigger: resizePngWithNativeImage receives an empty/invalid PNG buffer so createFromBuffer yields an empty image, or resize throws on non-positive dimensions.

Common situations: Chained after error 583 — original PNG was already corrupt; or height/width of 0 passed through.

Related errors


AI-assisted analysis of musistudio/claude-code-router@99f24806c6 (2026-08-27). Data as JSON: /api/errors/dbf1b7adc77e2995. Report an issue: GitHub.