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

  1. Broaden or simplify the query and re-run (check quoting of boolean operators like AND/OR)
  2. Re-run later if transient; verify NCBI availability with curl on the eutils endpoint
  3. Inspect the raw ESearch JSON to see the actual response shape
  4. Set NCBI_API_KEY to avoid rate-limit-induced error payloads
  5. 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

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/02e34837c7548e7e. Report an issue: GitHub.