{"record":{"id":"d3ab984ce334e71d","repo":"jackwener/OpenCLI","slug":"failed-to-export-the-generated-gemini-image","errorCode":null,"errorMessage":"Failed to export the generated Gemini image","messagePattern":"Failed to export the generated Gemini image","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/gemini/image.js","lineNumber":107,"sourceCode":"        const effectivePrompt = buildImagePrompt(prompt, {\n            ratio,\n            style: style || undefined,\n        });\n        if (startFresh)\n            await startNewGeminiChat(page);\n        const beforeUrls = await getGeminiVisibleImageUrls(page);\n        await sendGeminiMessage(page, effectivePrompt);\n        const urls = await waitForGeminiImages(page, beforeUrls, timeout);\n        const link = await currentGeminiLink(page);\n        if (!urls.length) {\n            throw new EmptyResultError('gemini image', `No generated image was detected. Open ${link} and check whether Gemini produced one.`);\n        }\n        if (skipDownload) {\n            return [{ status: '🎨 generated', file: '📁 -', link: `🔗 ${link}` }];\n        }\n        const assets = await exportGeminiImages(page, urls);\n        if (!assets.length) {\n            throw new CommandExecutionError('Failed to export the generated Gemini image', `Open ${link} and verify the image is visible, then retry.`);\n        }\n        const stamp = Date.now();\n        const results = [];\n        for (let index = 0; index < assets.length; index += 1) {\n            const asset = assets[index];\n            const base64 = asset.dataUrl.replace(/^data:[^;]+;base64,/, '');\n            const suffix = assets.length > 1 ? `_${index + 1}` : '';\n            const filePath = path.join(outputDir, `gemini_${stamp}${suffix}${extFromMime(asset.mimeType)}`);\n            await saveBase64ToFile(base64, filePath);\n            results.push({ status: '✅ saved', file: `📁 ${displayPath(filePath)}`, link: `🔗 ${link}` });\n        }\n        return results;\n    },\n});\n","sourceCodeStart":89,"sourceCodeEnd":122,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gemini/image.js#L89-L122","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nopencli gemini image --prompt \"a castle\" --timeout 15   // export fails, image still loading\n// after\nopencli gemini image --prompt \"a castle\" --timeout 90","handlingStrategy":"retry","validationCode":"// Prefer skip-download to isolate generation from export\nawait run(['gemini','image','--prompt',p,'--timeout','120','--sd']); // verify generation works first","typeGuard":"function hasAssets(a){ return Array.isArray(a) && a.length > 0 && a.every(x => typeof x.dataUrl === 'string' && x.dataUrl.startsWith('data:')); }","tryCatchPattern":"try {\n  return await run(['gemini','image','--prompt',p,'--timeout','120']);\n} catch (e) {\n  if (String(e.message).includes('Failed to export the generated Gemini image')) {\n    await sleep(5000); // let the image finish loading\n    return await run(['gemini','image','--prompt',p,'--timeout','180']);\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["export-failure","image-generation","network","cli"],"backgroundTag":"asset-export-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}