jackwener/OpenCLI · error · EmptyResultError
pubmed article
Error message
pubmed article
What it means
EmptyResultError('pubmed article') thrown at clis/pubmed/article.js:28 when eutilsFetch('efetch') succeeded but parseArticleXml returned null/undefined for the requested PMID. The CLI treats this as 'no data' rather than a crash: the XML came back but contained no parseable article matching the PMID.
Source
Thrown at clis/pubmed/article.js:28
description: 'Get detailed information for a PubMed article by PMID',
domain: 'pubmed.ncbi.nlm.nih.gov',
strategy: Strategy.PUBLIC,
browser: false,
defaultFormat: 'plain',
args: [
{ name: 'pmid', positional: true, required: true, help: 'PubMed ID, e.g. 37780221' },
{ name: 'full-abstract', type: 'boolean', default: false, help: 'Do not truncate the abstract in table output' },
],
columns: ['pmid', 'title', 'authors', 'journal', 'year', 'date', 'article_type', 'language', 'doi', 'pmc', 'affiliations', 'grants', 'mesh_terms', 'keywords', 'abstract', 'url'],
func: async (args) => {
const pmid = requirePmid(args.pmid);
const xml = await eutilsFetch('efetch', {
id: pmid,
rettype: 'abstract',
}, { retmode: 'xml', label: 'pubmed article' });
const article = parseArticleXml(xml, pmid);
if (!article) {
throw new EmptyResultError('pubmed article', `No article found for PMID ${pmid}.`);
}
if (!article.title) {
throw new CommandExecutionError(`pubmed article ${pmid} did not include a title`, 'PubMed EFetch response shape may have changed.');
}
const abstract = args['full-abstract'] ? article.abstract : truncateText(article.abstract, 500);
return [
{
pmid: article.pmid,
title: article.title,
authors: article.authors.join(', '),
journal: article.journal,
year: article.year,
date: article.date || null,
article_type: article.article_type,
language: article.language || null,
doi: article.doi || null,
pmc: article.pmc || null,
affiliations: article.affiliations || null,View on GitHub (pinned to 49907e53dc)
Solutions
- Verify the PMID exists by opening https://pubmed.ncbi.nlm.nih.gov/<pmid>/ in a browser
- Check the raw EFetch response (add debug logging on xml) to see if NCBI returned an error or empty document
- If you have a DOI or other id, resolve it to a PMID first via esearch before calling efetch
- Validate the PMID input (digits only) before calling the command
- Retry later if NCBI is having a transient issue; confirm status at the NCBI status page
Example fix
// before
const article = parseArticleXml(xml, pmid);
if (!article) {
throw new EmptyResultError('pubmed article', `No article found for PMID ${pmid}.`);
}
// after
if (!/^\d+$/.test(pmid)) {
throw new ArgumentError(`"${pmid}" is not a valid PMID (expected numeric id)`);
}
const article = parseArticleXml(xml, pmid);
if (!article) {
throw new EmptyResultError('pubmed article', `No article found for PMID ${pmid}.`);
} Defensive patterns
Strategy: validation
Validate before calling
// validate the PMID before calling the command
if (!/^\d{1,9}$/.test(pmid)) {
throw new Error(`"${pmid}" is not a numeric PMID`);
} Try / catch
try {
const article = await runCli('pubmed article', { pmid });
} catch (e) {
if (e instanceof EmptyResultError || /No article found/.test(e.message)) {
console.warn(`PMID ${pmid} not found in PubMed — verify the id.`);
return null;
}
throw e;
} Prevention
- Only pass numeric PMIDs (resolve DOIs via esearch first)
- Spot-check unknown PMIDs on the PubMed website before batch runs
- Log raw efetch XML when debugging to spot error documents
- Keep a list of withdrawn/suppressed PMIDs if reusing old datasets
When it happens
Trigger: parseArticleXml(xml, pmid) returns falsy because: (a) the PMID does not exist or was withdrawn/removed from PubMed, (b) EFetch returned an error XML (e.g. <eFetchResult> with no <PubmedArticle>) for an invalid id, (c) the rettype 'abstract' XML has a shape parseArticleXml does not recognize.
Common situations: Passing a DOI instead of a PMID; a typo'd or stale PMID from an old reference list; querying a book/in-process record whose XML differs; NCBI returns an error document for an id that was suppressed.
Related errors
- pubmed author
- pubmed citations
- pubmed clinical-trial
- No cruise departure port matching "${port}" (try a listed se
- devto/${id}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/ee7e0546e73f7f2d.
Report an issue: GitHub.