jackwener/OpenCLI · error · ArgumentError

${label} must be a positive integer

Error message

${label} must be a positive integer

What it means

normalizeLimit validates a numeric limit option: it must be an integer greater than 0, else this ArgumentError is thrown. It defaults the value when null/undefined and is called by the limit helpers and commands with a limit option.

Source

Thrown at clis/hltv/utils.js:66

  overpass: 'de_overpass',
  cache: 'de_cache',
  cobblestone: 'de_cobblestone',
  season: 'de_season',
  train: 'de_train',
  tuscan: 'de_tuscan',
  vertigo: 'de_vertigo',
};

export const VERSIONS = {
  both: null,
  cs2: 'CS2',
  csgo: 'CSGO',
};

export function normalizeLimit(value, defaultValue, maxValue, label = 'limit') {
  const raw = value ?? defaultValue;
  const n = Number(raw);
  if (!Number.isInteger(n) || n <= 0) throw new ArgumentError(`${label} must be a positive integer`);
  if (n > maxValue) throw new ArgumentError(`${label} must be <= ${maxValue}`);
  return n;
}

export function normalizeOffset(value, defaultValue = 0) {
  const raw = value ?? defaultValue;
  const n = Number(raw);
  if (!Number.isInteger(n) || n < 0) throw new ArgumentError('offset must be a non-negative integer');
  if (n % 100 !== 0) throw new ArgumentError('offset must be a multiple of 100');
  return n;
}

export function normalizeChoice(value, defaultValue, choices, label) {
  const raw = String(value ?? defaultValue);
  if (!Object.prototype.hasOwnProperty.call(choices, raw)) {
    throw new ArgumentError(`${label} must be one of: ${Object.keys(choices).join(', ')}`);
  }
  return raw;

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a positive integer (>=1), e.g. limit: 10
  2. Coerce CLI/config strings with Number() and validate before calling
  3. Use Math.trunc/Math.floor on computed values to guarantee integers
  4. Catch ArgumentError and fall back to the default limit

Example fix

// before
await run('search', { query: 'niko', limit: rawFlag }); // rawFlag is '20' (string)
// after
const n = Number(rawFlag);
await run('search', { query: 'niko', limit: Number.isInteger(n) && n > 0 ? n : 10 });
Defensive patterns

Strategy: validation

Validate before calling

function safeLimit(v, dflt = 10, max = 50) {
  const n = Number(v);
  return Number.isInteger(n) && n > 0 && n <= max ? n : dflt;
}
// args.limit = safeLimit(rawLimit);

Type guard

function isPositiveInt(v) { return typeof v === 'number' && Number.isInteger(v) && v > 0; }

Try / catch

try {
  await command(page, { ...args, limit });
} catch (err) {
  if (err instanceof ArgumentError && /must be a positive integer/.test(err.message)) {
    return command(page, { ...args, limit: 10 }); // fall back to default
  }
  throw err;
}

Prevention

When it happens

Trigger: Passing limit=0, a negative number, a non-integer like 2.5, a non-numeric string like 'ten', or NaN/Infinity to any command or helper accepting a limit option.

Common situations: CLI flag parsed from a string that was never converted to a number; computing a limit from a division producing a float; user enters 0 or negative 'to get everything'; JSON config containing a string limit.

Related errors


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