jackwener/OpenCLI · error · CommandExecutionError
Failed to export the generated Gemini image
Error message
Failed to export the generated Gemini image
What it means
Once image URLs are detected, gemini image exports them via exportGeminiImages (fetching data URLs); if export returns no assets despite URLs being found, it throws CommandExecutionError('Failed to export the generated Gemini image') with a hint to verify visibility and retry. This surfaces a download/export-stage failure separate from generation itself.
Source
Thrown at clis/gemini/image.js:107
const effectivePrompt = buildImagePrompt(prompt, {
ratio,
style: style || undefined,
});
if (startFresh)
await startNewGeminiChat(page);
const beforeUrls = await getGeminiVisibleImageUrls(page);
await sendGeminiMessage(page, effectivePrompt);
const urls = await waitForGeminiImages(page, beforeUrls, timeout);
const link = await currentGeminiLink(page);
if (!urls.length) {
throw new EmptyResultError('gemini image', `No generated image was detected. Open ${link} and check whether Gemini produced one.`);
}
if (skipDownload) {
return [{ status: '🎨 generated', file: '📁 -', link: `🔗 ${link}` }];
}
const assets = await exportGeminiImages(page, urls);
if (!assets.length) {
throw new CommandExecutionError('Failed to export the generated Gemini image', `Open ${link} and verify the image is visible, then retry.`);
}
const stamp = Date.now();
const results = [];
for (let index = 0; index < assets.length; index += 1) {
const asset = assets[index];
const base64 = asset.dataUrl.replace(/^data:[^;]+;base64,/, '');
const suffix = assets.length > 1 ? `_${index + 1}` : '';
const filePath = path.join(outputDir, `gemini_${stamp}${suffix}${extFromMime(asset.mimeType)}`);
await saveBase64ToFile(base64, filePath);
results.push({ status: '✅ saved', file: `📁 ${displayPath(filePath)}`, link: `🔗 ${link}` });
}
return results;
},
});
View on GitHub (pinned to 49907e53dc)
Solutions
- Open the link in the message, confirm the image is fully visible, then rerun the command (retry often succeeds once rendering completes)
- Increase --timeout so the image finishes loading before export is attempted
- If it persists consistently, check whether the Gemini DOM changed and update/patch exportGeminiImages selectors
- Skip download with the sd flag to confirm generation works and isolate the export stage
Example fix
// before opencli gemini image --prompt "a castle" --timeout 15 // export fails, image still loading // after opencli gemini image --prompt "a castle" --timeout 90
Defensive patterns
Strategy: retry
Validate before calling
// Prefer skip-download to isolate generation from export await run(['gemini','image','--prompt',p,'--timeout','120','--sd']); // verify generation works first
Type guard
function hasAssets(a){ return Array.isArray(a) && a.length > 0 && a.every(x => typeof x.dataUrl === 'string' && x.dataUrl.startsWith('data:')); } Try / catch
try {
return await run(['gemini','image','--prompt',p,'--timeout','120']);
} catch (e) {
if (String(e.message).includes('Failed to export the generated Gemini image')) {
await sleep(5000); // let the image finish loading
return await run(['gemini','image','--prompt',p,'--timeout','180']);
}
throw e;
} Prevention
- Use a longer --timeout so images fully load before the export step
- Retry once after a delay; export is sensitive to incomplete rendering
- Use the sd (skip download) flag to confirm generation succeeds independently of export
- If failures become consistent, suspect a Gemini DOM change affecting exportGeminiImages
When it happens
Trigger: Image elements were seen but their data could not be extracted: image not fully loaded when fetched, blob/src mutated between detection and export, network failure retrieving the data URL, or Gemini DOM change breaking the export extraction.
Common situations: Clicking/downloading too early while the image is still streaming; flaky network dropping the image fetch; Gemini UI update altering image element attributes the exporter relies on; large images timing out mid-extraction.
Related errors
- archive search request failed: ${error?.message || error}
- archive search returned malformed JSON: ${error?.message ||
- coingecko categories request failed: ${err?.message ?? err}
- coingecko trending request failed: ${error?.message || error
- FETCH_ERROR
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/d3ab984ce334e71d.
Report an issue: GitHub.