Hmbown/CodeWhale · error · Error

--days must be an integer from 1 through 90

Error message

--days must be an integer from 1 through 90

What it means

After parsing, `--days` is coerced with Number(raw); the guard requires Number.isInteger and a value from 1 through 90, else `--days must be an integer from 1 through 90`. A trailing `--days` with no value reads undefined → NaN → the same error. The bound exists because the value is interpolated into activeInstallsSql's `INTERVAL '${days - 1}' DAY` clause.

Source

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

  // 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`;
}

/** Newest ingested event of any kind — how stale the dataset is. */

View on GitHub (pinned to 8880682c63)

Solutions

  1. Pass an integer in range, e.g. `--days 30`
  2. If the flag is last on the line, remember it consumes the next token — supply the value
  3. For ranges beyond 90 days, query the Cloudflare SQL API directly rather than widening the guard

Example fix

# before
node scripts/report-active-installs.mjs --days 365
# after
node scripts/report-active-installs.mjs --days 90
Defensive patterns

Strategy: validation

Validate before calling

const rawIndex = argv.indexOf('--days');
const days = Number(argv[rawIndex + 1]);
if (!Number.isInteger(days) || days < 1 || days > 90) {
  console.error('--days must be an integer from 1 through 90');
  process.exit(2);
}

Try / catch

try {
  const { days } = parseArgs(argv);
} catch (error) {
  if (/--days/.test(error.message)) { console.error('Pass e.g. --days 30'); process.exit(2); }
  throw error;
}

Prevention

When it happens

Trigger: `--days abc`, `--days 0`, `--days 91`, `--days 30.5`, or `--days` as the last argument with the value missing.

Common situations: Asking for a quarter (91+) or a year of data; passing a float; forgetting the value in a CI script line.

Related errors


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