{"record":{"id":"4f2168bbcd07760e","repo":"chenglou/pretext","slug":"no-bundled-text-import-for-corpus-meta-id","errorCode":null,"errorMessage":"No bundled text import for corpus ${meta.id}","messagePattern":"No bundled text import for corpus (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"pages/corpus.ts","lineNumber":1042,"sourceCode":"      return myBadDeedsReturnToYouTeacher\n    case 'ko-unsu-joh-eun-nal':\n      return koUnsuJohEunNal\n    case 'ko-sonagi':\n      return koSonagi\n    case 'mixed-app-text':\n      return mixedAppText\n    case 'th-nithan-vetal-story-1':\n      return thNithanVetalStory1\n    case 'th-nithan-vetal-story-7':\n      return thNithanVetalStory7\n    case 'ur-chughd':\n      return urChughd\n    case 'zh-zhufu':\n      return zhZhufu\n    case 'zh-guxiang':\n      return zhGuxiang\n    default:\n      throw new Error(`No bundled text import for corpus ${meta.id}`)\n  }\n}\n\nasync function loadCorpus(meta: CorpusMeta): Promise<void> {\n  currentMeta = meta\n  const rawText = await loadText(meta)\n\n  updateTitle(meta)\n  configureControls(meta)\n  populateSelect(meta.id)\n\n  const font = buildFont(meta)\n  const lineHeight = getLineHeight(meta)\n  const direction = getDirection(meta)\n\n  if ('fonts' in document) {\n    await document.fonts.ready\n  }","sourceCodeStart":1024,"sourceCodeEnd":1060,"githubUrl":"https://github.com/chenglou/pretext/blob/ac49b09b7d83ede19581fa94a8b892b07d309baf/pages/corpus.ts#L1024-L1060","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add the missing text import at the top of corpus.ts and a matching `case '<id>': return <imported>` branch in loadText.","If the corpus is not ready, remove its entry from the sources JSON until the import lands.","Verify the id string matches exactly (case-sensitive, including hyphens) between sources and the switch case.","Rebuild/reload the page so the sources JSON and the script bundle are from the same commit."],"exampleFix":"// before\ncase 'zh-guxiang':\n  return zhGuxiang\ndefault:\n  throw new Error(`No bundled text import for corpus ${meta.id}`)\n\n// after (add the missing corpus)\nimport viSample from './corpora/vi-sample.txt'\n// ...\ncase 'vi-sample':\n  return viSample\ndefault:\n  throw new Error(`No bundled text import for corpus ${meta.id}`)","handlingStrategy":"validation","validationCode":"// Maintain a registry so sources and loadText stay in sync.\nconst CORPUS_TEXT_IMPORTS: Record<string, () => string> = {\n  'ar-al-bukhala': () => arAlBukhala,\n  'zh-guxiang': () => zhGuxiang,\n  // ...\n}\nfunction loadText(meta: CorpusMeta): string {\n  const factory = CORPUS_TEXT_IMPORTS[meta.id]\n  if (factory === undefined) throw new Error(`No bundled text import for corpus ${meta.id}`)\n  return factory()\n}","typeGuard":"// Ensure every source id has a text import at build time.\nfunction assertAllSourcesHaveText(sources: CorpusMeta[], ids: string[]): void {\n  const missing = sources.map(s => s.id).filter(id => !ids.includes(id))\n  if (missing.length > 0) throw new Error(`Missing imports: ${missing.join(', ')}`)\n}","tryCatchPattern":"// init() already catches this and calls setError; surface it clearly to the maintainer.\ntry {\n  await loadCorpus(selected)\n} catch (error) {\n  setError(error instanceof Error ? error.message : String(error))\n}","preventionTips":["When adding a corpus, update sources JSON, the text import, and the loadText branch in the same commit.","Add a unit test asserting every source id resolves through loadText.","Use a single registry object (id -> importer) instead of a switch to avoid forget-a-case bugs."],"tags":["corpus-page","maintainer-bug","data-consistency","switch"],"backgroundTag":null,"analyzedSha":"ac49b09b7d83ede19581fa94a8b892b07d309baf","analyzedAt":"2026-08-12T17:03:16.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}