jackwener/OpenCLI · error · EmptyResultError
pubmed search
Error message
pubmed search
What it means
Thrown by the 'pubmed search' command after the NCBI ESearch call. If the response lacks a valid esearchresult.idlist array it throws CommandExecutionError ('response shape may have changed'); if the id list is empty it throws EmptyResultError naming the query. It protects the downstream fetchSummaryRows step from undefined data.
Source
Thrown at clis/pubmed/search.js:71
yearTo,
articleType: args['article-type'],
hasAbstract: args['has-abstract'],
hasFullText: args['free-full-text'],
humanOnly: args['humans-only'],
englishOnly: args['english-only'],
});
const esearch = await eutilsFetch('esearch', {
term: searchQuery,
retmax: limit,
usehistory: 'y',
sort: sortMap[sort],
}, { label: 'pubmed search' });
const pmids = esearch?.esearchresult?.idlist;
if (!Array.isArray(pmids)) {
throw new CommandExecutionError('pubmed search did not return an id list', 'PubMed ESearch response shape may have changed.');
}
if (pmids.length === 0) {
throw new EmptyResultError('pubmed search', `No articles matched "${query}".`);
}
return fetchSummaryRows(pmids, 'pubmed search summary');
},
});
View on GitHub (pinned to 49907e53dc)
Solutions
- Broaden or simplify the query and re-run (check quoting of boolean operators like AND/OR)
- Re-run later if transient; verify NCBI availability with curl on the eutils endpoint
- Inspect the raw ESearch JSON to see the actual response shape
- Set NCBI_API_KEY to avoid rate-limit-induced error payloads
- Update the pubmed CLI/library if the E-utilities schema changed
Example fix
// before pubmed search '"ultra rare [phrase' --limit 5 // after pubmed search 'CRISPR AND cattle' --limit 5
Defensive patterns
Strategy: try-catch
Validate before calling
const res = await fetch(esearchUrl);
const body = await res.json();
if (!Array.isArray(body?.esearchresult?.idlist)) {
throw new Error('unexpected ESearch shape: ' + JSON.stringify(body).slice(0, 200));
} Type guard
function hasIdList(r) {
return r != null && typeof r === 'object'
&& r.esearchresult != null
&& Array.isArray(r.esearchresult.idlist);
} Try / catch
try {
const pmids = await pubmedSearch(query);
} catch (err) {
if (err instanceof EmptyResultError) {
console.warn(`no results for "${query}"`); // handle empty as normal case
} else if (err instanceof CommandExecutionError) {
console.error('PubMed ESearch failed:', err.detail);
} else { throw err; }
} Prevention
- Treat empty results as an expected branch, not a crash
- Validate the response shape before consuming nested fields
- Broaden queries before assuming an API failure
- Set NCBI_API_KEY to avoid throttling-related error payloads
- Pin/update the CLI version when NCBI changes E-utilities schemas
When it happens
Trigger: Running `pubmed search <query>` when NCBI returns an unexpected JSON body (schema change, error payload with HTTP 200, rate-limit HTML) or when the query matches zero articles.
Common situations: Overly specific queries returning nothing; NCBI E-utilities outages or throttling; proxies injecting error pages; E-utilities API changes after an NCBI update.
Related errors
- aibase news
- No items match "${query}" on archive.org.
- No series found for '${brand}'. Check the brand name spellin
- This series has no koubei rating yet.
- No hotels rendered (${totalText}). Try a broader destination
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/02e34837c7548e7e.
Report an issue: GitHub.