toeverything/AFFiNE · error · Error
Failed to generate PNG buffer from image
Error message
Failed to generate PNG buffer from image
What it means
Thrown in the Electron `captureArea` handler when `image.toPNG()` yields a null or zero-length buffer after a non-empty capture — PNG encoding of the captured frame failed. Screenshot capture for that area fails with this error rather than returning invalid data to the renderer.
Source
Thrown at packages/frontend/apps/electron/src/main/ui/handlers.ts:231
if (e.sender.session.availableSpellCheckerLanguages.includes(language)) {
e.sender.session.setSpellCheckerLanguages([language, 'en-US']);
}
},
captureArea: async (e, { x, y, width, height }: Electron.Rectangle) => {
const image = await e.sender.capturePage({
x: Math.floor(x),
y: Math.floor(y),
width: Math.floor(width),
height: Math.floor(height),
});
if (image.isEmpty()) {
throw new Error('Image is empty or invalid');
}
const buffer = image.toPNG();
if (!buffer || !buffer.length) {
throw new Error('Failed to generate PNG buffer from image');
}
clipboard.writeImage(nativeImage.createFromBuffer(buffer));
},
} satisfies NamespaceHandlers;
View on GitHub (pinned to b6de0ad51b)
Solutions
- Retry with a valid image; the native image object could not be converted to PNG.
- Check that the image data is complete and in a supported format.
- Recreate the native image from the source buffer before converting.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at packages/frontend/apps/electron/src/main/ui/handlers.ts:317 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of toeverything/AFFiNE@b6de0ad51b (2026-08-18).
Data as JSON: /api/errors/c7ae82bc446ceb38.
Report an issue: GitHub.