jackwener/OpenCLI · error · CommandExecutionError
Gemini image detection returned a malformed result
Error message
Gemini image detection returned a malformed result
What it means
Thrown when the image-detection page.evaluate returns a non-array (caught by requireGeminiArrayResult with label 'Gemini image detection') or an array containing non-string URLs. The library extracts generated-image URLs from the response DOM and validates the shape before returning them to callers like waitForGeminiImages.
Source
Thrown at clis/gemini/utils.js:2367
const width = img.naturalWidth || img.width || 0;
const height = img.naturalHeight || img.height || 0;
if (!src) continue;
if (alt.includes('avatar') || alt.includes('logo') || alt.includes('icon')) continue;
// A placeholder still streaming its bytes reports complete false and
// naturalWidth 0 while laying out at full size, so the size gate below
// would accept it and the export step would save a blank frame (#2245).
if (!img.complete || !img.naturalWidth) continue;
if (width < 128 && height < 128) continue;
if (seen.has(src)) continue;
seen.add(src);
urls.push(src);
}
return urls;
})()
`);
const urls = requireGeminiArrayResult(result, 'Gemini image detection');
if (!urls.every((url) => typeof url === 'string')) {
throw new CommandExecutionError('Gemini image detection returned a malformed result');
}
return urls;
}
/** Cheap generation probe: the snapshot read walks the whole transcript. */
export async function isGeminiGenerating(page) {
let result;
try {
result = await page.evaluate(`(() => ${isGeneratingExpression()})()`);
}
catch (error) {
const message = error instanceof Error ? error.message : String(error);
throw new CommandExecutionError('Gemini generation probe failed', message);
}
const value = unwrapGeminiEvaluateResult(result, 'Gemini generation probe');
if (typeof value !== 'boolean') {
throw new CommandExecutionError('Gemini generation probe returned a malformed result');
}
return value;View on GitHub (pinned to 49907e53dc)
Solutions
- Wait until the assistant response has fully rendered before extracting images (use waitForGeminiTranscript first).
- Log the raw evaluate result and update the image-extraction script selectors to the current Gemini image DOM.
- Coerce entries to strings (img.src) and filter nulls inside the in-page script.
- Catch CommandExecutionError and treat as 'no images yet', retrying with the existing poll loop.
Defensive patterns
Strategy: try-catch
Type guard
function isImageUrlArray(v) {
return Array.isArray(v) && v.every((u) => typeof u === 'string' && /^https?:|^data:|^blob:/.test(u));
} Try / catch
try {
urls = await getGeminiImageUrls(page);
} catch (e) {
if (String(e.message).includes('malformed result')) urls = []; // no images yet
else throw e;
} Prevention
- Only extract images after the assistant response fully rendered.
- Run waitForGeminiTranscript before image polling.
- Update image-extraction selectors when Gemini changes image embedding.
- Treat empty/malformed results as 'no images' in polling loops.
When it happens
Trigger: Calling image extraction/waitForGeminiImages when the in-page script returns undefined/null instead of an array (script error, no conversation DOM) or rows that are objects/null instead of URL strings — usually because Gemini changed how generated images are embedded (new container, blob URLs, srcset).
Common situations: Gemini UI update to image carousels; page polled before any response rendered; conversation using an image format the extractor doesn't recognize; evaluate unwrapping producing undefined on script exception.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Gemini conversation list returned a malformed row
- Gemini visible turns returned a malformed row
- Gemini model discovery returned a malformed row
- Gemini transcript lines returned a malformed row
- Gemini page snapshot returned a malformed result
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/50ec546141d05ef5.
Report an issue: GitHub.