jackwener/OpenCLI · warning · EmptyResultError

openFDA returned no labels matching "${query}".

Error message

openFDA returned no labels matching "${query}".

What it means

drug-label queries openFDA's /drug/label.json endpoint; when the response contains no results array entries it throws EmptyResultError with this message. openFDA treats 'no matches' as success, so the CLI must detect the empty list itself. The message echoes the user's query so it is clear what found nothing.

Source

Thrown at clis/openfda/drug-label.js:48

    columns: [
        'rank', 'id', 'brandName', 'genericName', 'manufacturer',
        'productType', 'route', 'productNdc', 'pharmClass',
        'purpose', 'indications', 'warnings', 'dosage', 'effectiveTime',
    ],
    func: async (args) => {
        const query = requireString(args.query, 'query');
        const limit = requireBoundedInt(args.limit, 5, 25);
        const brand = `openfda.brand_name:"${query}"`;
        const generic = `openfda.generic_name:"${query}"`;
        // URLSearchParams encodes spaces/operators in ways openFDA's Lucene
        // parser handles poorly. Keep the OR literal visible and encode only
        // each clause, matching food-recall's manual +AND+ handling.
        const search = `${encodeURIComponent(brand)}+OR+${encodeURIComponent(generic)}`;
        const url = `${OPENFDA_BASE}/drug/label.json?search=${search}&limit=${limit}`;
        const body = await openfdaFetch(url, 'openfda drug-label');
        const list = Array.isArray(body?.results) ? body.results : [];
        if (!list.length) {
            throw new EmptyResultError('openfda drug-label', `openFDA returned no labels matching "${query}".`);
        }
        return list.map((r, i) => {
            const o = r?.openfda ?? {};
            // pharm_class fields: epc (established pharmacologic class) is the
            // most user-meaningful — fall back through moa/cs/pe in that order.
            const pharmClass = firstOrNull(o.pharm_class_epc) ?? firstOrNull(o.pharm_class_moa)
                ?? firstOrNull(o.pharm_class_cs) ?? firstOrNull(o.pharm_class_pe);
            return {
                rank: i + 1,
                id: r?.id ?? null,
                brandName: firstOrNull(o.brand_name),
                genericName: firstOrNull(o.generic_name),
                manufacturer: firstOrNull(o.manufacturer_name),
                productType: firstOrNull(o.product_type),
                route: joinOrNull(o.route),
                productNdc: firstOrNull(o.product_ndc),
                pharmClass,
                purpose: firstOrNull(r.purpose),

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check spelling of brand/generic names and retry with the generic (INN) name, which is more consistently indexed.
  2. Broaden the query — drop the less-important of the two name clauses and search a single term.
  3. Lower or raise the limit and confirm the request URL returns data directly via curl against api.fda.gov.
  4. Fall back to another openFDA endpoint (e.g. drug/ndc.json) if the drug truly has no label records.

Example fix

// before
fetchDrugLabel({ brand: 'Amoxycilin' }); // typo -> no results
// after
fetchDrugLabel({ generic: 'amoxicillin' });
Defensive patterns

Strategy: try-catch

Validate before calling

function validateDrugQuery({ brand, generic }) {
  if (!brand && !generic) throw new Error('provide --brand or --generic');
  for (const v of [brand, generic]) {
    if (v != null && (!/^[a-zA-Z0-9\- ]+$/.test(v) || v.length > 100)) {
      throw new Error(`suspicious drug name: ${v}`);
    }
  }
  return true;
}

Type guard

function hasResults(body) {
  return body != null && Array.isArray(body.results) && body.results.length > 0;
}

Try / catch

try {
  const labels = await fetchDrugLabel(opts);
} catch (e) {
  if (e instanceof EmptyResultError) return []; // render 'no labels found'
  throw e;
}

Prevention

When it happens

Trigger: The brand and/or generic drug names supplied produce an OR search over drug label records that matches zero labels — e.g. a misspelled drug name, an obsolete/withdrawn product, or a combination no label record contains.

Common situations: Typo in the drug name ('amoxycillin' vs 'amoxicillin'); searching for a very new drug not yet in openFDA labels; querying a brand name that exists only in a different openFDA dataset (e.g. NDC directory).

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


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