Hmbown/CodeWhale · error · Error

unknown argument: ${arg}

Error message

unknown argument: ${arg}

What it means

report-active-installs.mjs parseArgs accepts exactly two flags: `--json` (boolean) and `--days <n>` (which consumes the next argv token). Any other argument throws `unknown argument: ${arg}` before any Cloudflare request is made.

Source

Thrown at telemetry-ingest/scripts/report-active-installs.mjs:47

export function parseArgs(argv) {
  // 15 = 14 complete UTC days plus the partial current day, the smallest
  // window that fills both sides of the 7-day trend.
  let days = 15;
  let json = false;
  for (let index = 0; index < argv.length; index += 1) {
    const arg = argv[index];
    if (arg === "--json") {
      json = true;
      continue;
    }
    if (arg === "--days") {
      const raw = argv[index + 1];
      index += 1;
      days = Number(raw);
      continue;
    }
    throw new Error(`unknown argument: ${arg}`);
  }
  if (!Number.isInteger(days) || days < 1 || days > 90) {
    throw new Error("--days must be an integer from 1 through 90");
  }
  return { days, json };
}

export function activeInstallsSql(days) {
  return `SELECT
  toDate(timestamp) AS day,
  count(DISTINCT index1) AS active_installs,
  sum(_sample_interval) AS sessions_started
FROM codewhale_telemetry
WHERE timestamp >= toStartOfDay(NOW()) - INTERVAL '${days - 1}' DAY
  AND blob1 = 'session_start'
GROUP BY day
ORDER BY day DESC
FORMAT JSON`;

View on GitHub (pinned to 8880682c63)

Solutions

  1. Remove the unsupported argument and use only `--json` and `--days N`
  2. Re-check the parser loop at report-active-installs.mjs:47 when adding new flags
  3. Prefer `--help` output (or reading the parser) over guessing flag names

Example fix

# before
node scripts/report-active-installs.mjs --day 30
# after
node scripts/report-active-installs.mjs --days 30
Defensive patterns

Strategy: validation

Validate before calling

const ALLOWED = new Set(['--json', '--days']);
const argv = process.argv.slice(2);
const bad = argv.filter((a, i) => !ALLOWED.has(a) && !(i > 0 && argv[i - 1] === '--days'));
if (bad.length) {
  console.error(`unknown argument(s): ${bad.join(' ')} — supported: --json, --days <1-90>`);
  process.exit(2);
}

Try / catch

try {
  parseArgs(argv);
} catch (error) {
  if (/^unknown argument:/.test(error.message)) { console.error('usage: --json [--days N]'); process.exit(2); }
  throw error;
}

Prevention

When it happens

Trigger: Running the script with a positional argument, a flag from another report script (e.g. --format), or a typo such as `--day 30` instead of `--days 30`.

Common situations: Copy-pasting CLI examples across telemetry scripts; aliases or wrappers that append extra flags.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/d46ffa98b1559908. Report an issue: GitHub.