jackwener/OpenCLI · error · CommandExecutionError
Google Scholar search returned an unexpected payload shape
Error message
Google Scholar search returned an unexpected payload shape
What it means
The `google-scholar search` command evaluates an in-page script that must return an object `{ items: [...], resultCount }`. This guard throws a CommandExecutionError when the evaluated wrapper is null, not an object, or its `items` is not an array — i.e. the browser evaluation itself failed rather than returning an empty result set.
Source
Thrown at clis/google-scholar/search.js:63
const citedText = normalize(container.querySelector('.gs_fl a[href*="cites"]')?.textContent);
const cited = citedText.match(/(\\d+)/)?.[1] || '0';
results.push({
rank: results.length + 1,
title,
authors: authors.slice(0, 80),
source: source.slice(0, 60),
year,
cited,
url,
});
if (results.length >= ${limit}) break;
}
return { items: results, resultCount: resultCards.length };
})()
`);
if (!wrapper || typeof wrapper !== 'object' || !Array.isArray(wrapper.items)) {
throw new CommandExecutionError('Google Scholar search returned an unexpected payload shape');
}
if (wrapper.items.length === 0) {
if (Number(wrapper.resultCount) > 0) {
throw new CommandExecutionError('Google Scholar result cards were present but no rows could be extracted');
}
throw new EmptyResultError('google-scholar/search', 'Try a different query or check whether Google Scholar returned a CAPTCHA.');
}
return wrapper.items;
},
});
View on GitHub (pinned to 49907e53dc)
Solutions
- Re-run the command — transient browser/page-state failures usually succeed on retry.
- Check the browser automation setup (headless browser installed, driver versions compatible).
- If it reproduces on every query, inspect whether scholar.google.com is returning an error/CAPTCHA page that breaks the evaluate script, and update the command.
- Catch CommandExecutionError and fall back to a different search backend.
Example fix
// before
const wrapper = null; // page.evaluate returned undefined -> throws
// after
if (!wrapper || typeof wrapper !== 'object' || !Array.isArray(wrapper.items)) {
return []; // or retry the navigation before surfacing the error
} Defensive patterns
Strategy: retry
Type guard
const isSearchPayload = (w) => !!w && typeof w === 'object' && Array.isArray(w.items);
Try / catch
try {
return await run('google-scholar search', query);
} catch (e) {
if (/unexpected payload shape/.test(e.message)) {
await sleep(2000); return await run('google-scholar search', query); // one retry
}
throw e;
} Prevention
- Keep browser automation stack up to date.
- Ensure the headless browser is healthy (no stale tabs/crashes) between runs.
- Check for CAPTCHA pages before parsing when loops fail repeatedly.
When it happens
Trigger: Calling `google-scholar search <query>` where `page.evaluate` returns null/undefined or a non-object: the evaluate string failed to execute (script error, sandbox/CSP block), the browser page was torn down, or the driver returned an unexpected serialization.
Common situations: Browser crashed or tab navigated mid-evaluation; headless environment where `page.evaluate` on a template string is unsupported/misconfigured; CSP or page state preventing script execution; driver/automation-library version mismatch changing evaluate return semantics.
Related errors
- No profile found for: ${author}
- Could not load Google Scholar profile for: ${author}
- No papers found for: ${data.name || author}
- google images returned an unexpected page-state payload shap
- Barchart greeks returned an unreadable options payload
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/abff0622221352b3.
Report an issue: GitHub.