moeru-ai/airi · error · Error

Unsupported capture format

Error message

Unsupported capture format "${requestedFormat}". Expected "png" or "avif".

What it means

Thrown by the capture.ts CLI guard when the --format flag value is neither 'png' nor 'avif'. The script validates argv before invoking captureBrowserRoots because the AVIF path installs an @napi-rs/image transformer and the PNG path must not, so the format must be an exact lowercase literal.

Solutions

  1. Pass a supported literal: pnpm capture -- --format avif (or --format png, the default when the flag is omitted).
  2. Lowercase the value in wrappers: --format "${FORMAT,,}".
  3. If you need another format, capture as png and convert afterwards with your own tooling.
  4. Check for missing flag values (a trailing --format with nothing after it also lands here).

Example fix

# before
pnpm capture -- --format jpg # throws: Unsupported capture format "jpg"

# after
pnpm capture -- --format avif
Defensive patterns

Strategy: validation

Validate before calling

// In wrappers/CI before invoking capture.ts:
const FORMAT = (process.env.CAPTURE_FORMAT ?? 'png').toLowerCase()
if (!['png', 'avif'].includes(FORMAT)) {
  throw new Error(`CAPTURE_FORMAT must be 'png' or 'avif', got '${FORMAT}'`)
}

Type guard

const CAPTURE_FORMATS = ['png', 'avif'] as const
const isCaptureFormat = (value: string): value is typeof CAPTURE_FORMATS[number] =>
  (CAPTURE_FORMATS as readonly string[]).includes(value)

Prevention

When it happens

Trigger: Running the script with --format jpg, --format webp, --format PNG (uppercase), or --format with a missing value (undefined fails the includes check); a wrapper/CI script templating the format from a variable with unexpected values.

Common situations: CI pipelines parameterizing screenshot format; contributors assuming webp/jpeg support because AVIF is supported; shell scripts passing user input straight through; casing mistakes.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of moeru-ai/airi@677329427f (2026-08-18). Data as JSON: /api/errors/6d5e74f8ff7cb6f7. Report an issue: GitHub.

Appendix: source

Thrown at packages/scenarios-stage-tamagotchi-browser/scripts/capture.ts:59

  }

  const avifBuffer = await transformer.avif({
    quality: avifQuality,
    speed: avifSpeed,
  })

  await writeFile(derivedFilePath, avifBuffer)
  await rm(artifact.filePath, { force: true })

  return {
    ...artifact,
    filePath: derivedFilePath,
    format: 'avif',
  }
}

if (!['png', 'avif'].includes(requestedFormat)) {
  throw new Error(`Unsupported capture format "${requestedFormat}". Expected "png" or "avif".`)
}

if (!routePath?.startsWith('/')) {
  throw new Error(`Unsupported route path "${routePath}". Route paths must start with "/".`)
}

if (outputDirFlagIndex >= 0 && !argv[outputDirFlagIndex + 1]) {
  throw new Error('Missing value for --output-dir.')
}

if (settleMsFlagIndex >= 0 && !argv[settleMsFlagIndex + 1]) {
  throw new Error('Missing value for --settle-ms.')
}

if (avifMaxWidthFlagIndex >= 0 && !argv[avifMaxWidthFlagIndex + 1]) {
  throw new Error('Missing value for --avif-max-width.')
}

View on GitHub (pinned to 677329427f)