jackwener/OpenCLI · error · CommandExecutionError
Could not find search result at index ${index + 1}
Error message
Could not find search result at index ${index + 1} What it means
In google-scholar/cite.js, clicking the Nth result's Cite link is done inside page.evaluate which returns {ok, reason} or a falsy value; if the click did not succeed the code throws CommandExecutionError `Could not find search result at index ${index+1}` (or the page's own reason). The index is 0-based internally but reported 1-based to the user.
Source
Thrown at clis/google-scholar/cite.js:41
await page.goto(`https://scholar.google.com/scholar?q=${encodeURIComponent(query)}&hl=en`);
await page.wait(3);
const clicked = await page.evaluate(`(() => {
var cites = document.querySelectorAll('a.gs_or_cit');
if (cites.length <= ${index}) return { ok: false, reason: 'result not found at index ${index + 1}' };
var titleEl = document.querySelectorAll('.gs_r.gs_or.gs_scl')[${index}];
var title = '';
if (titleEl) {
var t = titleEl.querySelector('.gs_rt a, h3 a');
title = t ? t.textContent.trim() : '';
}
cites[${index}].click();
return { ok: true, title: title };
})()`);
if (!clicked?.ok) {
throw new CommandExecutionError(clicked?.reason || `Could not find search result at index ${index + 1}`);
}
await page.wait(2);
const formatMap = { bibtex: 'BibTeX', endnote: 'EndNote', refman: 'RefMan', refworks: 'RefWorks' };
const formatLabel = formatMap[format] || 'BibTeX';
const citeUrl = await page.evaluate(`(() => {
var links = document.querySelectorAll('#gs_cit a.gs_citi');
for (var i = 0; i < links.length; i++) {
if (links[i].textContent.trim() === '${formatLabel}') return links[i].href;
}
return null;
})()`);
if (!citeUrl) {
throw new CommandExecutionError(`Could not find ${formatLabel} citation link for result ${index + 1}`);
}View on GitHub (pinned to 49907e53dc)
Solutions
- Use a smaller/valid index within the returned result count
- Catch the error and retry after re-running the search and waiting for results
- Check for a CAPTCHA/unusual-traffic page and slow down request rate
- Ensure the search step succeeded and wait for results to render before citing
Example fix
// before
await scholarCite(page, 15, 'bibtex'); // assumes 16+ results
// after
const results = await scholarSearch(page, query);
if (15 < results.length) await scholarCite(page, 15, 'bibtex');
else console.warn('result index out of range'); Defensive patterns
Strategy: validation
Validate before calling
if (!Number.isInteger(index) || index < 0 || index >= results.length) throw new Error(`index ${index} out of range (0..${results.length - 1})`); Type guard
const isValidIndex = (i, n) => Number.isInteger(i) && i >= 0 && i < n;
Try / catch
try { await scholarCite(page, i, fmt); }
catch (e) { if (e instanceof CommandExecutionError && /Could not find search result/.test(e.message)) { await page.wait(3); /* retry or skip */ } else throw e; } Prevention
- Cap indices at the number of results actually returned by search
- Detect CAPTCHA/unusual-traffic pages and back off
- Wait for results to render before issuing cite calls
When it happens
Trigger: Calling cite with an index beyond the number of results on the page (e.g. index 15 when only 8 results rendered); Scholar showing a CAPTCHA/error page; results not yet loaded before evaluate runs.
Common situations: Scripting citation downloads for a long list of indices without checking result count; rate limiting leading to an 'unusual traffic' page with zero results; slow load causing evaluate to run before results render.
Related errors
- Could not find ${formatLabel} citation link for result ${ind
- settings click failed
- sidebar-toggle failed
- 无法在聊天列表中找到该用户,候选人可能不在当前列表中
- 找不到消息输入框
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/4b23a967a2fce075.
Report an issue: GitHub.