Crosstalk-Solutions/project-nomad · error · Error

Unexpected FDA manifest format: missing or invalid "export_d

Error message

Unexpected FDA manifest format: missing or invalid "export_date"

What it means

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.

Source

Thrown at admin/util/drug_labels.ts:263

  const root = json as Record<string, unknown>
  const results = root['results'] as Record<string, unknown> | undefined
  if (!results || typeof results !== 'object') {
    throw new Error('Unexpected FDA manifest format: missing "results"')
  }

  const drug = results['drug'] as Record<string, unknown> | undefined
  if (!drug || typeof drug !== 'object') {
    throw new Error('Unexpected FDA manifest format: missing "results.drug"')
  }

  const label = drug['label'] as Record<string, unknown> | undefined
  if (!label || typeof label !== 'object') {
    throw new Error('Unexpected FDA manifest format: missing "results.drug.label"')
  }

  const export_date = label['export_date']
  if (typeof export_date !== 'string' || export_date.trim() === '') {
    throw new Error('Unexpected FDA manifest format: missing or invalid "export_date"')
  }

  const total_records = label['total_records']
  if (typeof total_records !== 'number') {
    throw new Error('Unexpected FDA manifest format: missing or invalid "total_records"')
  }

  const rawPartitions = label['partitions']
  if (!Array.isArray(rawPartitions) || rawPartitions.length === 0) {
    throw new Error(
      'Unexpected FDA manifest format: "partitions" is missing or empty'
    )
  }

  const partitions: DrugLabelPartition[] = []
  for (const p of rawPartitions as unknown[]) {
    if (typeof p !== 'object' || p === null) {
      process.stderr.write('[parseDrugLabelManifest] Skipping non-object partition\n')

View on GitHub (pinned to 0bd1c6f4f9)

Solutions

  1. Inspect the actual payload: log or curl the manifest URL and check results.drug.label.export_date to confirm what the API returned.
  2. If FDA renamed the field (e.g. export_date -> last_updated), update the key in parseDrugLabelManifest and any related types.
  3. If the field can legitimately be absent, decide on a fallback (e.g. default to partition file dates) instead of throwing.
  4. Pin/verify the API version or endpoint URL so schema drift is detected early.

Example fix

// before
const export_date = label['export_date']
if (typeof export_date !== 'string' || export_date.trim() === '') {
  throw new Error('Unexpected FDA manifest format: missing or invalid "export_date"')
}
// after (accept ISO date or numeric epoch, with explicit schema error otherwise)
const rawDate = label['export_date'] ?? label['last_updated']
const export_date = typeof rawDate === 'string' ? rawDate
  : typeof rawDate === 'number' ? new Date(rawDate).toISOString() : null
if (!export_date) {
  throw new Error(`Unexpected FDA manifest format: "export_date" was ${JSON.stringify(rawDate)}`)
}
Defensive patterns

Strategy: validation

Validate before calling

// Before calling fetchManifest, verify the raw shape
const raw = await fetchManifestJson(url)
const label = raw?.results?.drug?.label
if (typeof label?.['export_date'] !== 'string' || !label['export_date'].trim()) {
  // skip import, log schema drift, alert — don't call parseDrugLabelManifest
}

Type guard

function hasExportDate(v: unknown): v is { export_date: string } {
  return typeof v === 'object' && v !== null
    && typeof (v as any).export_date === 'string'
    && (v as any).export_date.trim() !== ''
}

Try / catch

try {
  const manifest = await parseDrugLabelManifest(json)
} catch (e) {
  if (e instanceof Error && e.message.includes('export_date')) {
    // log raw json keys to detect FDA schema drift
  }
  throw e
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of Crosstalk-Solutions/project-nomad@0bd1c6f4f9 (2026-08-27). Data as JSON: /api/errors/9bc415565a78dad7. Report an issue: GitHub.