jackwener/OpenCLI · error · ArgumentError

offset must be a multiple of 100

Error message

offset must be a multiple of 100

What it means

normalizeOffset additionally requires the offset to be a multiple of 100 because the upstream HLTV stats API pages in blocks of exactly 100 results. Any valid non-negative integer that is not divisible by 100 triggers this error.

Source

Thrown at clis/hltv/utils.js:75

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

export function parseNumber(value) {
  const raw = String(value ?? '').replace(/\s+/g, ' ').trim();
  if (!raw || raw === '-' || raw.toLowerCase() === 'n/a') return null;
  const match = raw.replace(/,/g, '').match(/-?\d+(?:\.\d+)?/);
  if (!match) return null;
  const n = Number(match[0]);
  return Number.isFinite(n) ? n : null;

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Step the offset by 100 between pages (offset = 0, 100, 200, ...)
  2. If using a custom limit, still align offsets to multiples of 100
  3. Track page count and compute offset as pageCount * 100

Example fix

// before
for (let offset = 0; ; offset += 50) { ... }
// after
for (let offset = 0; ; offset += 100) { ... }
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(opts.offset);
if (!Number.isInteger(n) || n < 0 || n % 100 !== 0) throw new Error('offset must be a non-negative multiple of 100');

Type guard

const isAlignedOffset = (v) => Number.isInteger(Number(v)) && Number(v) >= 0 && Number(v) % 100 === 0;

Try / catch

try {
  return await hltv.stats({ offset });
} catch (e) {
  if (e.name === 'ArgumentError' && e.message.includes('multiple of 100')) {
    return hltv.stats({ offset: Math.floor(offset / 100) * 100 });
  }
  throw e;
}

Prevention

When it happens

Trigger: --offset 150, --offset 250, or programmatic offsets computed from a limit other than 100 (e.g. offset += 50 per page).

Common situations: Users combining offset with a custom limit like --limit 50 and stepping offset by 50; porting code from APIs with arbitrary offsets.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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