{"record":{"id":"9bc415565a78dad7","repo":"Crosstalk-Solutions/project-nomad","slug":"unexpected-fda-manifest-format-missing-or-invalid","errorCode":null,"errorMessage":"Unexpected FDA manifest format: missing or invalid \"export_date\"","messagePattern":"Unexpected FDA manifest format: missing or invalid \"export_date\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"admin/util/drug_labels.ts","lineNumber":263,"sourceCode":"  const root = json as Record<string, unknown>\n  const results = root['results'] as Record<string, unknown> | undefined\n  if (!results || typeof results !== 'object') {\n    throw new Error('Unexpected FDA manifest format: missing \"results\"')\n  }\n\n  const drug = results['drug'] as Record<string, unknown> | undefined\n  if (!drug || typeof drug !== 'object') {\n    throw new Error('Unexpected FDA manifest format: missing \"results.drug\"')\n  }\n\n  const label = drug['label'] as Record<string, unknown> | undefined\n  if (!label || typeof label !== 'object') {\n    throw new Error('Unexpected FDA manifest format: missing \"results.drug.label\"')\n  }\n\n  const export_date = label['export_date']\n  if (typeof export_date !== 'string' || export_date.trim() === '') {\n    throw new Error('Unexpected FDA manifest format: missing or invalid \"export_date\"')\n  }\n\n  const total_records = label['total_records']\n  if (typeof total_records !== 'number') {\n    throw new Error('Unexpected FDA manifest format: missing or invalid \"total_records\"')\n  }\n\n  const rawPartitions = label['partitions']\n  if (!Array.isArray(rawPartitions) || rawPartitions.length === 0) {\n    throw new Error(\n      'Unexpected FDA manifest format: \"partitions\" is missing or empty'\n    )\n  }\n\n  const partitions: DrugLabelPartition[] = []\n  for (const p of rawPartitions as unknown[]) {\n    if (typeof p !== 'object' || p === null) {\n      process.stderr.write('[parseDrugLabelManifest] Skipping non-object partition\\n')","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/Crosstalk-Solutions/project-nomad/blob/0bd1c6f4f9888d577fe232de06ac144bb8337131/admin/util/drug_labels.ts#L245-L281","documentation":"This error is thrown by parseDrugLabelManifest in admin/util/drug_labels.ts when validating the FDA drug label download manifest. After confirming results.drug.label is an object, it requires label['export_date'] to be a non-empty string. If the field is missing, not a string, or whitespace-only, the manifest is considered malformed and parsing aborts.","triggerScenarios":"Calling fetchManifest() (or anything consuming parseDrugLabelManifest) against an FDA openFDA API response where results.drug.label exists but export_date is absent, null, a number/timestamp instead of a string, or an empty/whitespace string (e.g. upstream API schema change or a mocked test fixture).","commonSituations":"FDA changes the bulk-download manifest schema between releases; a proxy or cache strips fields; tests use a hand-written fixture missing export_date; the code hits a different API version (e.g. staging vs production endpoint) with a slightly different shape.","solutions":["Inspect the actual payload: log or curl the manifest URL and check results.drug.label.export_date to confirm what the API returned.","If FDA renamed the field (e.g. export_date -> last_updated), update the key in parseDrugLabelManifest and any related types.","If the field can legitimately be absent, decide on a fallback (e.g. default to partition file dates) instead of throwing.","Pin/verify the API version or endpoint URL so schema drift is detected early."],"exampleFix":"// before\nconst export_date = label['export_date']\nif (typeof export_date !== 'string' || export_date.trim() === '') {\n  throw new Error('Unexpected FDA manifest format: missing or invalid \"export_date\"')\n}\n// after (accept ISO date or numeric epoch, with explicit schema error otherwise)\nconst rawDate = label['export_date'] ?? label['last_updated']\nconst export_date = typeof rawDate === 'string' ? rawDate\n  : typeof rawDate === 'number' ? new Date(rawDate).toISOString() : null\nif (!export_date) {\n  throw new Error(`Unexpected FDA manifest format: \"export_date\" was ${JSON.stringify(rawDate)}`)\n}","handlingStrategy":"validation","validationCode":"// Before calling fetchManifest, verify the raw shape\nconst raw = await fetchManifestJson(url)\nconst label = raw?.results?.drug?.label\nif (typeof label?.['export_date'] !== 'string' || !label['export_date'].trim()) {\n  // skip import, log schema drift, alert — don't call parseDrugLabelManifest\n}","typeGuard":"function hasExportDate(v: unknown): v is { export_date: string } {\n  return typeof v === 'object' && v !== null\n    && typeof (v as any).export_date === 'string'\n    && (v as any).export_date.trim() !== ''\n}","tryCatchPattern":"try {\n  const manifest = await parseDrugLabelManifest(json)\n} catch (e) {\n  if (e instanceof Error && e.message.includes('export_date')) {\n    // log raw json keys to detect FDA schema drift\n  }\n  throw e\n}","preventionTips":["Pin the FDA bulk-download endpoint/version in config","Keep a recorded real-manifest fixture in tests and assert parseDrugLabelManifest succeeds against it","Log the received label keys when validation fails to catch renames early"],"tags":["fda","manifest","schema-validation","typescript"],"backgroundTag":"schema-validation-failed","analyzedSha":"0bd1c6f4f9888d577fe232de06ac144bb8337131","analyzedAt":"2026-08-27T05:34:15.424Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}