chenglou/pretext · error · Error

Unknown corpus ${options.id}. Available corpora: ${sources.m

Error message

Unknown corpus ${options.id}. Available corpora: ${sources.map(source => source.id).join(', ')}

What it means

Thrown at the top level of corpus-font-matrix.ts after parseOptions has returned. The parsed --id is looked up against corpora/sources.json (loadSources + sources.find). If no source matches, throws listing all source ids. This is the font-matrix analogue of [31] and uses the SAME sources.json availability list.

Source

Thrown at scripts/corpus-font-matrix.ts:438

    .map(([diffPx, widths]) => `${diffPx > 0 ? '+' : ''}${diffPx}px: ${widths.join(', ')}`)
    .join(' | ')
}

function printSummary(summary: MatrixSummary): void {
  console.log(`${summary.corpusId} — ${summary.title}`)
  console.log(`widths: ${summary.widths.join(', ')}`)
  for (const variant of summary.variants) {
    console.log(`  ${variant.label}: ${variant.exactCount}/${variant.widthCount} exact | ${variant.mismatches.length} nonzero`)
    console.log(`    ${bucketMismatches(variant.mismatches)}`)
  }
}

const options = parseOptions()
options.port = await getAvailablePort(options.port === 0 ? null : options.port)
const sources = await loadSources()
const meta = sources.find(source => source.id === options.id)
if (meta === undefined) {
  throw new Error(`Unknown corpus ${options.id}. Available corpora: ${sources.map(source => source.id).join(', ')}`)
}

const variants = FONT_MATRIX[options.id]
if (variants === undefined) {
  throw new Error(`No font matrix configured for ${options.id}. Available corpora: ${Object.keys(FONT_MATRIX).join(', ')}`)
}

const widths = getSweepWidths(meta, options)
const lock = await acquireBrowserAutomationLock(options.browser)
const session = createBrowserSession(options.browser)
let serverProcess: ChildProcess | null = null

try {
  const pageServer = await ensurePageServer(options.port, '/corpus', process.cwd())
  serverProcess = pageServer.process
  const baseUrl = `${pageServer.baseUrl}/corpus`
  const variantResults: VariantResult[] = []

View on GitHub (pinned to ac49b09b7d)

Solutions

  1. Use an id that exists in corpora/sources.json (the error lists them).
  2. If adding a new font-matrix corpus, add the sources.json entry FIRST — both this lookup and the [38] check depend on it.
  3. Copy the id verbatim; the find is case-sensitive equality.

Example fix

// before
bun run scripts/corpus-font-matrix.ts --id=ja-kumo
// after
bun run scripts/corpus-font-matrix.ts --id=ja-kumo-no-ito
Defensive patterns

Strategy: validation

Validate before calling

const sources = await Bun.file('corpora/sources.json').json() as { id: string }[]
const SOURCE_IDS = new Set(sources.map(s => s.id))
function assertInSources(id: string): void {
  if (!SOURCE_IDS.has(id)) {
    throw new Error(`Unknown corpus ${id}. Valid sources: ${[...SOURCE_IDS].join(', ')}`)
  }
}

Type guard

function isInSources(id: string, known: Set<string>): boolean {
  return known.has(id)
}

Prevention

When it happens

Trigger: options.id passed parseOptions (so it is non-null) but sources.find(s => s.id === options.id) returns undefined. Triggers on a typo, a case mismatch, or an id that exists in FONT_MATRIX but was never added to sources.json (a configuration inconsistency).

Common situations: An id was added to FONT_MATRIX without a matching sources.json entry; a renamed corpus where one file was updated but not the other; case-sensitive typo.

Related errors


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