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

  1. Pass whole numbers only: --limit 10 --offset 0
  2. Quote-free numeric env vars without units or whitespace
  3. Coerce with Math.floor/parseInt and validate in your wrapper before calling
  4. 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

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/ca32ee526d28c83c. Report an issue: GitHub.