chenglou/pretext · error · Error

Unsupported --method ${requestedMethod}; expected span or ra

Error message

Unsupported --method ${requestedMethod}; expected span or range

What it means

Thrown at module top-level of corpus-check.ts after parsing --method. The diagnostic extractor used by corpus-check has exactly two modes — 'span' (wrap each line in a span and read offsets) and 'range' (use Range objects to walk the DOM). Any other value is rejected before any browser work starts. Per AGENTS.md, span is the default and range is the cross-check, especially on Safari around preserved spaces.

Source

Thrown at scripts/corpus-check.ts:285

      const summary = mismatch.oursSegments
        .map(segment => `${JSON.stringify(segment.text)}@${segment.width.toFixed(2)}/${segment.domWidth.toFixed(2)}${segment.isSpace ? ':space' : ''}`)
        .join(' | ')
      console.log(`  ours segments: ${summary}`)
    }
  } else if (report.firstMismatch !== null && report.firstMismatch !== undefined) {
    console.log(`  first mismatch L${report.firstMismatch.line}`)
    console.log(`  ours:    ${JSON.stringify(report.firstMismatch.ours.slice(0, 120))}`)
    console.log(`  browser: ${JSON.stringify(report.firstMismatch.browser.slice(0, 120))}`)
  }
}

let serverProcess: ChildProcess | null = null
const browser = parseBrowser(parseStringFlag('browser'))
const requestedPort = parseNumberFlag('port', Number.parseInt(process.env['CORPUS_CHECK_PORT'] ?? '0', 10))
const timeoutMs = parseNumberFlag('timeout', Number.parseInt(process.env['CORPUS_CHECK_TIMEOUT_MS'] ?? '180000', 10))
const requestedMethod = parseStringFlag('method')
if (requestedMethod !== null && requestedMethod !== 'span' && requestedMethod !== 'range') {
  throw new Error(`Unsupported --method ${requestedMethod}; expected span or range`)
}
const overrideOptions: CorpusOverrideOptions = {
  font: parseStringFlag('font'),
  lineHeight: parseOptionalNumberFlag('lineHeight'),
  method: requestedMethod as 'span' | 'range' | null,
  sliceStart: parseOptionalNumberFlag('sliceStart'),
  sliceEnd: parseOptionalNumberFlag('sliceEnd'),
}
const sources = await loadSources()
const id = parseStringFlag('id')

if (id === null) {
  throw new Error(`Missing --id. Available corpora: ${sources.map(source => source.id).join(', ')}`)
}

const meta = sources.find(source => source.id === id)
if (meta === undefined) {
  throw new Error(`Unknown corpus ${id}. Available corpora: ${sources.map(source => source.id).join(', ')}`)

View on GitHub (pinned to ac49b09b7d)

Solutions

  1. Use `--method=span` (default, fastest, preferred) or `--method=range` (cross-check, recommended for Safari preserved-space diagnostics).
  2. Omit --method entirely to take the default span path.
  3. Match the casing exactly — the comparison is strict equality, no lowercasing.

Example fix

// before
bun run scripts/corpus-check.ts --id=ja-kumo-no-ito --method=SPAN
// after
bun run scripts/corpus-check.ts --id=ja-kumo-no-ito --method=span
Defensive patterns

Strategy: validation

Validate before calling

const CORPUS_METHODS = new Set(['span', 'range'])
function normalizeMethod(raw: string | null): 'span' | 'range' | null {
  if (raw === null) return null
  if (!CORPUS_METHODS.has(raw)) {
    throw new Error(`Unsupported --method ${raw}; expected one of ${[...CORPUS_METHODS].join(', ')}`)
  }
  return raw as 'span' | 'range'
}

Type guard

function isCorpusMethod(value: string): value is 'span' | 'range' {
  return value === 'span' || value === 'range'
}

Prevention

When it happens

Trigger: parseStringFlag('method') returns a non-null string that is neither 'span' nor 'range'. Triggers on `--method=div`, `--method=text`, `--method=SPAN` (case-sensitive — uppercase is rejected), or a copy-paste from documentation describing a different tool's extraction modes.

Common situations: Confusing this with a different tool's method names; passing uppercase (the check is case-sensitive, unlike parseBrowser which lowercases); typo from a shell variable.

Related errors


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