{"record":{"id":"59ef1505c9b699b9","repo":"chenglou/pretext","slug":"no-corpora-found","errorCode":null,"errorMessage":"No corpora found","messagePattern":"No corpora found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pages/corpus.ts","lineNumber":1129,"sourceCode":"\nslider.addEventListener('input', () => {\n  setWidth(Number.parseInt(slider.value, 10))\n})\n\nselect.addEventListener('change', () => {\n  navigateToCorpus(select.value)\n})\n\nwindow.__CORPUS_REPORT__ = withRequestId({ status: 'error', message: 'Pending initial layout' })\nstats.textContent = 'Loading...'\nclearNavigationReport()\npublishNavigationPhase('loading', requestId)\n\nasync function init(): Promise<void> {\n  try {\n    corpusList = await loadSources()\n    if (corpusList.length === 0) {\n      throw new Error('No corpora found')\n    }\n\n    const selected = corpusList.find(meta => meta.id === requestedCorpusId) ?? corpusList[0]!\n    await loadCorpus(selected)\n  } catch (error) {\n    const message = error instanceof Error ? error.message : String(error)\n    setError(message)\n  }\n}\n\nvoid init()\n","sourceCodeStart":1111,"sourceCodeEnd":1141,"githubUrl":"https://github.com/chenglou/pretext/blob/ac49b09b7d83ede19581fa94a8b892b07d309baf/pages/corpus.ts#L1111-L1141","documentation":"Thrown in init() after await loadSources() returns: if the corpus metadata array is empty, there is nothing to display and the page cannot proceed. Unlike the other corpus errors this one is fully expected to be caught — init wraps it in try/catch and calls setError(message), so it renders as an error status in the UI rather than crashing the script. It distinguishes 'sources fetch returned valid JSON but zero entries' from a fetch failure (which would throw earlier).","triggerScenarios":"loadSources() successfully fetches and parses the sources JSON, but the parsed array is empty (length 0). This happens when the sources manifest is an empty array, or when a build step stripped all entries, or when a filter removed everything.","commonSituations":"The sources JSON was replaced with [] during a refactor; a CI build generated an empty manifest; the dev server is serving a stale/empty manifest from a different branch; a conditional inclusion removed all corpora for the current build configuration.","solutions":["Inspect the sources JSON that loadSources() fetches and confirm it contains the expected corpus entries.","Ensure the page is served from the correct working directory where the sources manifest is populated.","If you intentionally removed corpora, re-add at least one entry so the page has a default selection.","Check the network tab for the sources fetch response body to rule out a proxy truncating it to []."],"exampleFix":"// before\nconst sourcesData = await fetch('sources.json').then(r => r.json())\nreturn sourcesData as CorpusMeta[]\n\n// after\nconst sourcesData = await fetch('sources.json').then(r => r.json())\nif (!Array.isArray(sourcesData) || sourcesData.length === 0) {\n  throw new Error('Sources manifest is missing or empty')\n}\nreturn sourcesData as CorpusMeta[]","handlingStrategy":"validation","validationCode":"// Validate the fetched sources before returning.\nasync function loadSources(): Promise<CorpusMeta[]> {\n  const data = await fetch('/sources.json').then(r => r.json())\n  if (!Array.isArray(data) || data.length === 0) {\n    throw new Error('Sources manifest is missing or empty')\n  }\n  return data\n}","typeGuard":"function isNonEmptyCorpusList(value: unknown): value is CorpusMeta[] {\n  return Array.isArray(value) && value.length > 0 &&\n    value.every(item => typeof item === 'object' && item !== null && 'id' in item)\n}","tryCatchPattern":"// init() already wraps this; the error is shown via setError.\ntry {\n  corpusList = await loadSources()\n  if (corpusList.length === 0) throw new Error('No corpora found')\n  await loadCorpus(corpusList[0]!)\n} catch (error) {\n  setError(error instanceof Error ? error.message : String(error))\n}","preventionTips":["Keep the sources manifest under version control and review changes that empty it.","Serve the page from the repo root so the sources JSON path resolves.","Add a CI check that the built sources manifest is non-empty."],"tags":["corpus-page","data-empty","init","config"],"backgroundTag":null,"analyzedSha":"ac49b09b7d83ede19581fa94a8b892b07d309baf","analyzedAt":"2026-08-12T17:03:16.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}