{"record":{"id":"38c92d5555e68acb","repo":"jackwener/OpenCLI","slug":"openfda-returned-no-food-recall-records-matching-t","errorCode":null,"errorMessage":"openFDA returned no food recall records matching the filter.","messagePattern":"openFDA returned no food recall records matching the filter\\.","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/openfda/food-recall.js","lineNumber":44,"sourceCode":"        'productDescription', 'reasonForRecall', 'productQuantity',\n        'distributionPattern', 'reportDate', 'recallInitiationDate', 'terminationDate',\n    ],\n    func: async (args) => {\n        const limit = requireBoundedInt(args.limit, 10, 100);\n        const filters = [];\n        if (args.query) filters.push(String(args.query).trim());\n        if (args.status) filters.push(`status:\"${String(args.status).trim()}\"`);\n        if (args.classification) filters.push(`classification:\"${String(args.classification).trim()}\"`);\n        // URLSearchParams percent-encodes the `+AND+` separator that openFDA's\n        // Lucene parser treats specially, so build the query string by hand.\n        const qs = filters.length\n            ? `search=${filters.map(f => encodeURIComponent(f)).join('+AND+')}&limit=${limit}`\n            : `limit=${limit}`;\n        const url = `${OPENFDA_BASE}/food/enforcement.json?${qs}`;\n        const body = await openfdaFetch(url, 'openfda food-recall');\n        const list = Array.isArray(body?.results) ? body.results : [];\n        if (!list.length) {\n            throw new EmptyResultError('openfda food-recall', 'openFDA returned no food recall records matching the filter.');\n        }\n        return list.map((r, i) => ({\n            rank: i + 1,\n            recallNumber: r?.recall_number ?? null,\n            status: r?.status ?? null,\n            classification: r?.classification ?? null,\n            voluntary: r?.voluntary_mandated ?? null,\n            recallingFirm: r?.recalling_firm ?? null,\n            city: r?.city ?? null,\n            state: r?.state ?? null,\n            country: r?.country ?? null,\n            productDescription: r?.product_description ?? null,\n            reasonForRecall: r?.reason_for_recall ?? null,\n            productQuantity: r?.product_quantity ?? null,\n            distributionPattern: r?.distribution_pattern ?? null,\n            reportDate: r?.report_date ?? null,\n            recallInitiationDate: r?.recall_initiation_date ?? null,\n            terminationDate: r?.termination_date ?? null,","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/openfda/food-recall.js#L26-L62","documentation":"food-recall queries openFDA's /food/enforcement.json endpoint and throws EmptyResultError when the filtered result list is empty. Because openFDA returns HTTP 404 for zero matches (converted by openfdaFetch) and also allows genuinely empty arrays, the CLI normalizes both cases into this single 'no records' error. The message reflects the user's filter(s) yielding nothing.","triggerScenarios":"Filters like classification, status, date range, or a search term for /food/enforcement.json match zero recall records — e.g. filtering recalls for a product never recalled, or a date window with no enforcement actions.","commonSituations":"Narrow date range (last week) with no food recalls; filtering on a classification/status combination that never co-occurs; a product name spelled differently in FDA records ('Hy-Vee' vs brand spellings).","solutions":["Widen the date range or drop the most restrictive filter and re-run.","Verify the exact terminology FDA uses (recall classification I/II/III, status 'ongoing'/'completed') via a direct curl to api.fda.gov.","Search by a broader product keyword instead of an exact brand string.","Treat the empty result as a valid business outcome in the calling script rather than an exception."],"exampleFix":"// before\nfetchFoodRecalls({ state: 'CA', from: '2026-08-25', to: '2026-08-26' }); // too narrow\n// after\nfetchFoodRecalls({ state: 'CA', from: '2026-08-01', to: '2026-08-29' });","handlingStrategy":"try-catch","validationCode":"function validateRecallFilter(f = {}) {\n  const validClass = ['I', 'II', 'III'];\n  if (f.classification && !validClass.includes(f.classification)) {\n    throw new Error(`classification must be one of ${validClass.join('/')}`);\n  }\n  if (f.from && f.to && f.from > f.to) throw new Error('date range inverted');\n  return true;\n}","typeGuard":"function hasResults(body) {\n  return body != null && Array.isArray(body.results) && body.results.length > 0;\n}","tryCatchPattern":"try {\n  const rows = await fetchFoodRecalls(filter);\n} catch (e) {\n  if (e instanceof EmptyResultError) return []; // no recalls matched\n  throw e;\n}","preventionTips":["Widen date windows; recall data is sparse week to week.","Use FDA terminology (classification I/II/III, status ongoing/completed).","Test filters with a direct curl to /food/enforcement.json before scripting.","Treat empty results as a business outcome, not a crash."],"tags":["empty-results","openfda","api","filter"],"backgroundTag":"empty-result-set","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}