chenglou/pretext · error · Error
No corpora found
Error message
No corpora found
What it means
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).
Source
Thrown at pages/corpus.ts:1129
slider.addEventListener('input', () => {
setWidth(Number.parseInt(slider.value, 10))
})
select.addEventListener('change', () => {
navigateToCorpus(select.value)
})
window.__CORPUS_REPORT__ = withRequestId({ status: 'error', message: 'Pending initial layout' })
stats.textContent = 'Loading...'
clearNavigationReport()
publishNavigationPhase('loading', requestId)
async function init(): Promise<void> {
try {
corpusList = await loadSources()
if (corpusList.length === 0) {
throw new Error('No corpora found')
}
const selected = corpusList.find(meta => meta.id === requestedCorpusId) ?? corpusList[0]!
await loadCorpus(selected)
} catch (error) {
const message = error instanceof Error ? error.message : String(error)
setError(message)
}
}
void init()
View on GitHub (pinned to ac49b09b7d)
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 [].
Example fix
// before
const sourcesData = await fetch('sources.json').then(r => r.json())
return sourcesData as CorpusMeta[]
// after
const sourcesData = await fetch('sources.json').then(r => r.json())
if (!Array.isArray(sourcesData) || sourcesData.length === 0) {
throw new Error('Sources manifest is missing or empty')
}
return sourcesData as CorpusMeta[] Defensive patterns
Strategy: validation
Validate before calling
// Validate the fetched sources before returning.
async function loadSources(): Promise<CorpusMeta[]> {
const data = await fetch('/sources.json').then(r => r.json())
if (!Array.isArray(data) || data.length === 0) {
throw new Error('Sources manifest is missing or empty')
}
return data
} Type guard
function isNonEmptyCorpusList(value: unknown): value is CorpusMeta[] {
return Array.isArray(value) && value.length > 0 &&
value.every(item => typeof item === 'object' && item !== null && 'id' in item)
} Try / catch
// init() already wraps this; the error is shown via setError.
try {
corpusList = await loadSources()
if (corpusList.length === 0) throw new Error('No corpora found')
await loadCorpus(corpusList[0]!)
} catch (error) {
setError(error instanceof Error ? error.message : String(error))
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid widths parameter: ${raw}
- Failed to measure ${currentMeta?.id ?? 'corpus'} @ ${width}
- No bundled text import for corpus ${meta.id}
- Invalid ACCURACY_CHECK_PORT: ${requestedPortRaw}
- Invalid value for --${name}: ${raw}
AI-assisted analysis of chenglou/pretext@ac49b09b7d (2026-08-12).
Data as JSON: /api/errors/59ef1505c9b699b9.
Report an issue: GitHub.