itwanger/toBeBetterJavaer · error · Error

Unknown option: ${arg}

Error message

Unknown option: ${arg}

What it means

Thrown by the argument parser of scripts/convert-mdnice-images-to-cdn.js when a command-line token starts with '-' but does not match any recognized flag (--write, --env, --domains, --prefix, --concurrency, --limit, --verbose, --help/-h). The parser walks argv token by token, and any leading-dash token that falls through every branch hits this guard. It exists to fail fast on typos instead of silently treating the token as a target path.

Source

Thrown at scripts/convert-mdnice-images-to-cdn.js:93

    } else if (arg.startsWith("--domains=")) {
      options.domains = parseList(arg.slice("--domains=".length));
    } else if (arg === "--prefix") {
      options.prefix = requireValue(argv, i);
      i += 1;
    } else if (arg.startsWith("--prefix=")) {
      options.prefix = arg.slice("--prefix=".length);
    } else if (arg === "--concurrency") {
      options.concurrency = parsePositiveInt(requireValue(argv, i), "--concurrency");
      i += 1;
    } else if (arg.startsWith("--concurrency=")) {
      options.concurrency = parsePositiveInt(arg.slice("--concurrency=".length), "--concurrency");
    } else if (arg === "--limit") {
      options.limit = parsePositiveInt(requireValue(argv, i), "--limit");
      i += 1;
    } else if (arg.startsWith("--limit=")) {
      options.limit = parsePositiveInt(arg.slice("--limit=".length), "--limit");
    } else if (arg.startsWith("-")) {
      throw new Error(`Unknown option: ${arg}`);
    } else {
      options.targets.push(path.resolve(ROOT_DIR, arg));
    }
  }

  if (options.targets.length === 0) {
    options.targets.push(DEFAULT_TARGET);
  }

  return options;
}

function requireValue(argv, index) {
  const value = argv[index + 1];
  if (!value || value.startsWith("-")) {
    throw new Error(`Missing value for ${argv[index]}`);
  }
  return value;

View on GitHub (pinned to 6617f5fd0b)

Solutions

  1. Run `node scripts/convert-mdnice-images-to-cdn.js --help` and correct the flag name to one of the supported options
  2. When invoking through npm, use `npm run images:cdn -- <flags>` so flags reach the script
  3. Remember there is no --dry-run flag: omit --write for a dry run

Example fix

// before
node scripts/convert-mdnice-images-to-cdn.js --dry-run --writ

// after (dry run is the default; typo fixed)
node scripts/convert-mdnice-images-to-cdn.js --verbose
Defensive patterns

Strategy: validation

Validate before calling

// Pre-flight: whitelist allowed flags before invoking
const ALLOWED = new Set(["--write", "verbose", "--env", "--domains", "--prefix", "--concurrency", "--limit", "--help", "-h"]);
const flags = args.filter((a) => a.startsWith("-") && !a.includes("="));
const bad = flags.filter((f) => !ALLOWED.has(f));
if (bad.length) throw new Error(`Check these flags first: ${bad.join(", ")}`);

Try / catch

catch (err) { if (err.message.startsWith("Unknown option:")) { printHelp-ish guidance: run with --help; } else throw err; }

Prevention

When it happens

Trigger: Running `node scripts/convert-mdnice-images-to-cdn.js --writ` (typo), `--dry-run` (unsupported flag), or `-x`. Also `--limit 5 --dry` where the second unknown flag aborts the run. Note only tokens starting with '-' throw; non-dash tokens are pushed into options.targets as file/dir paths.

Common situations: Typoing --verbose/--write; assuming a dry-run flag exists (dry-run is the default without --write); passing an npm script flag without the `--` separator, e.g. `npm run images:cdn --write` instead of `npm run images:cdn -- --write` so npm consumes or mangles it; passing a negative-looking path.

Related errors


AI-assisted analysis of itwanger/toBeBetterJavaer@6617f5fd0b (2026-08-14). Data as JSON: /api/errors/7e79aee03baae160. Report an issue: GitHub.