JuliusBrussee/caveman · error · Error

--days must be an integer from 1 to 3660

Error message

--days must be an integer from 1 to 3660

What it means

The --days flag must be a decimal integer between 1 and 3660 inclusive; anything else (non-numeric, zero, negative, floats, or > 3660) throws. Use --all-time instead of a huge --days value for unbounded windows.

Solutions

  1. Pass a plain integer 1–3660: `--days 30`
  2. Use `--all-time` instead of a very large or zero --days value
  3. Clamp/compute the value in the calling script before invoking, e.g. Math.min(Math.max(days,1),3660)

Example fix

// before
myapp stats --days 0
// after
myapp stats --all-time
Defensive patterns

Strategy: validation

Validate before calling

if (raw !== undefined && !/^\d+$/u.test(raw)) throw new Error("--days must be an integer");
const days = Number(raw);
if (days < 1 || days > 3660) throw new Error("--days must be 1..3660");

Try / catch

try {
  const opts = parseStatsOptions(["--days", raw]);
} catch (e) {
  if (e.message === "--days must be an integer from 1 to 3660") {
    console.error("pass an integer 1-3660, or use --all-time"); process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: `--days 0`, `--days -5`, `--days 4000`, `--days 7.5`, `--days week`, or a value with units like `--days 30d`.

Common situations: Trying to request 'all time' with --days 0 (the correct flag is --all-time); copying a duration with a unit suffix from another tool's CLI; scripts computing a window that overflows 3660 (10 years).

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/e15fbe66d532dda0. Report an issue: GitHub.

Appendix: source

Thrown at packages/cli/src/stats-cli.ts:44

  plain: boolean;
  open: boolean;
  out?: string;
  filters: string[];
};

export function parseStatsOptions(argv: string[]): StatsCLIOptions {
  const result: StatsCLIOptions = { json: false, plain: false, open: false, filters: [] };
  const seen = new Set<string>();
  const valueFlags = new Set(["--days", "--provider", "--model", "--agent", "--auth", "--out"]);
  for (let i = 0; i < argv.length; i++) {
    const arg = argv[i]!;
    if (seen.has(arg)) throw new Error(`duplicate ${arg}`);
    seen.add(arg);
    if (valueFlags.has(arg)) {
      const value = argv[++i];
      if (!value || value.startsWith("--") || /[\u0000-\u001f\u007f]/u.test(value)) throw new Error(`${arg} requires a value`);
      if (arg === "--days" && (!/^\d+$/u.test(value) || Number(value) < 1 || Number(value) > 3660)) {
        throw new Error("--days must be an integer from 1 to 3660");
      }
      if (arg === "--out") result.out = value;
      else result.filters.push(arg, value);
    } else if (arg === "--json") result.json = true;
    else if (arg === "--plain" || arg === "--no-open") result.plain = true;
    else if (arg === "--open") result.open = true;
    else if (arg === "--all-time") result.filters.push("--days", "0");
    else throw new Error(`unknown option ${arg}`);
  }
  if (seen.has("--days") && seen.has("--all-time")) throw new Error("choose --days or --all-time");
  if (result.plain && result.open) throw new Error("choose --plain or --open");
  if (result.json && result.open) throw new Error("--json cannot open a browser");
  return result;
}

type StatsMetrics = {
  requests: number;
  successful_requests: number;

View on GitHub (pinned to 3ee70a1026)