chenglou/pretext · critical · Error

No bundled text import for corpus ${meta.id}

Error message

No bundled text import for corpus ${meta.id}

What it means

Thrown by loadText() in its default switch case: the corpus metadata list (from sources JSON) contains an id that has no corresponding text-import case in loadText(). It is an internal consistency defect — someone registered a new corpus entry in sources without adding its bundled text import and case branch. The error is caught by init()'s try/catch and surfaced via setError, so the page shows an error state rather than a blank screen.

Source

Thrown at pages/corpus.ts:1042

      return myBadDeedsReturnToYouTeacher
    case 'ko-unsu-joh-eun-nal':
      return koUnsuJohEunNal
    case 'ko-sonagi':
      return koSonagi
    case 'mixed-app-text':
      return mixedAppText
    case 'th-nithan-vetal-story-1':
      return thNithanVetalStory1
    case 'th-nithan-vetal-story-7':
      return thNithanVetalStory7
    case 'ur-chughd':
      return urChughd
    case 'zh-zhufu':
      return zhZhufu
    case 'zh-guxiang':
      return zhGuxiang
    default:
      throw new Error(`No bundled text import for corpus ${meta.id}`)
  }
}

async function loadCorpus(meta: CorpusMeta): Promise<void> {
  currentMeta = meta
  const rawText = await loadText(meta)

  updateTitle(meta)
  configureControls(meta)
  populateSelect(meta.id)

  const font = buildFont(meta)
  const lineHeight = getLineHeight(meta)
  const direction = getDirection(meta)

  if ('fonts' in document) {
    await document.fonts.ready
  }

View on GitHub (pinned to ac49b09b7d)

Solutions

  1. Add the missing text import at the top of corpus.ts and a matching `case '<id>': return <imported>` branch in loadText.
  2. If the corpus is not ready, remove its entry from the sources JSON until the import lands.
  3. Verify the id string matches exactly (case-sensitive, including hyphens) between sources and the switch case.
  4. Rebuild/reload the page so the sources JSON and the script bundle are from the same commit.

Example fix

// before
case 'zh-guxiang':
  return zhGuxiang
default:
  throw new Error(`No bundled text import for corpus ${meta.id}`)

// after (add the missing corpus)
import viSample from './corpora/vi-sample.txt'
// ...
case 'vi-sample':
  return viSample
default:
  throw new Error(`No bundled text import for corpus ${meta.id}`)
Defensive patterns

Strategy: validation

Validate before calling

// Maintain a registry so sources and loadText stay in sync.
const CORPUS_TEXT_IMPORTS: Record<string, () => string> = {
  'ar-al-bukhala': () => arAlBukhala,
  'zh-guxiang': () => zhGuxiang,
  // ...
}
function loadText(meta: CorpusMeta): string {
  const factory = CORPUS_TEXT_IMPORTS[meta.id]
  if (factory === undefined) throw new Error(`No bundled text import for corpus ${meta.id}`)
  return factory()
}

Type guard

// Ensure every source id has a text import at build time.
function assertAllSourcesHaveText(sources: CorpusMeta[], ids: string[]): void {
  const missing = sources.map(s => s.id).filter(id => !ids.includes(id))
  if (missing.length > 0) throw new Error(`Missing imports: ${missing.join(', ')}`)
}

Try / catch

// init() already catches this and calls setError; surface it clearly to the maintainer.
try {
  await loadCorpus(selected)
} catch (error) {
  setError(error instanceof Error ? error.message : String(error))
}

Prevention

When it happens

Trigger: A sources JSON entry whose 'id' field has no matching case in the loadText switch (lines 1004-1043). For example, adding { "id": "vi-sample" } to the sources file without importing the text and adding `case 'vi-sample': return viSample`. Also triggers if an id has a typo mismatch between sources and the switch.

Common situations: A maintainer added a corpus to the sources manifest as part of a half-finished change; an id was renamed in one place but not the other; merge conflict resolution kept the sources entry but dropped the switch case. End users only see it if a stale/partial build of the page is served.

Related errors


AI-assisted analysis of chenglou/pretext@ac49b09b7d (2026-08-12). Data as JSON: /api/errors/4f2168bbcd07760e. Report an issue: GitHub.