jackwener/OpenCLI · error · ArgumentError
must be an integer
Error message
must be an integer
What it means
ArgumentError thrown by normalizeInteger when a numeric option (limit, offset, maxScrolls, pageScrolls, pageTimeoutMs, or delayMinMs) is not a whole number after Number() coercion. The library validates all pagination/timing flags upfront so scraping never starts with ambiguous input.
Source
Thrown at clis/grok/export-all.js:16
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, AuthRequiredError, EmptyResultError, TimeoutError } from '@jackwener/opencli/errors';
import fs from 'node:fs';
import {
normalizeConversationRows,
normalizeManifestRows,
requireBooleanEvaluateResult,
requireObjectEvaluateResult,
} from './export-utils.js';
import { GROK_DOMAIN, GROK_URL } from './utils.js';
function normalizeInteger(value, defaultValue, label, { min = 0, max = Number.MAX_SAFE_INTEGER } = {}) {
const raw = value ?? defaultValue;
const n = Number(raw);
if (!Number.isInteger(n)) {
throw new ArgumentError(label, `must be an integer`);
}
if (n < min) {
throw new ArgumentError(label, `must be >= ${min}`);
}
if (n > max) {
throw new ArgumentError(label, `must be <= ${max}`);
}
return n;
}
async function waitRandom(page, minMs, maxMs) {
if (maxMs <= 0) return;
const span = Math.max(0, maxMs - minMs);
const ms = minMs + Math.floor(Math.random() * (span + 1));
if (ms > 0) await page.wait(ms / 1000);
}
function readManifest(manifestPath, { offset, limit }) {View on GitHub (pinned to 49907e53dc)
Solutions
- Pass whole numbers only: --limit 10 --offset 0
- Quote-free numeric env vars without units or whitespace
- Coerce with Math.floor/parseInt and validate in your wrapper before calling
- Check that a default value being supplied is an integer
Example fix
// before
cli.exportAll({ limit: '5.5' });
// after
cli.exportAll({ limit: Number.parseInt('5.5', 10) }); // 5 Defensive patterns
Strategy: validation
Validate before calling
function assertInt(v, label) { const n = Number(v); if (!Number.isInteger(n)) throw new Error(`${label} must be an integer, got ${JSON.stringify(v)}`); return n; } Type guard
const isInt = (v) => typeof v === 'number' && Number.isInteger(v);
Try / catch
try { await cli.exportAll(opts); } catch (e) { if (e.name === 'ArgumentError' && /integer/.test(e.message)) { console.error(`Bad numeric option: ${e.message}`); } else throw e; } Prevention
- Parse CLI/env values with Number.parseInt/parseFloat before passing
- Strip units and whitespace from numeric env vars
- Add pre-call validation of all numeric options
- Favor documented defaults over hand-computed values
When it happens
Trigger: Passing any non-integer value (e.g. '3.5', 'abc', '', NaN) to limit/offset/maxScrolls/pageScrolls/pageTimeoutMs/delayMinMs in clis/grok/export-all.js.
Common situations: CLI flags like --limit=1.5 or --offset=oops; environment variables with stray characters; JS callers passing strings like '10px' or undefined-derived NaN values.
Understand the failure class
Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.
Related errors
- ${label} must be a positive integer
- ${label} must be an integer between ${min} and ${max}, got $
- archive snapshots url cannot be empty
- archive snapshots limit must be a positive integer
- archive snapshots limit must be <= 1000
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/ca32ee526d28c83c.
Report an issue: GitHub.