jackwener/OpenCLI · error · ArgumentError

boss ${name} must be <= ${max}

Error message

boss ${name} must be <= ${max}

What it means

readPositiveInteger validates CLI numeric options (limit, pageNum, currentPage) before they reach a BOSS API URL. When a max bound is supplied and the parsed value exceeds it, the library throws ArgumentError to stop an out-of-range request that the API would reject or that would flood results. It is a client-side input validation guard, not a network failure.

Source

Thrown at clis/boss/utils.js:26

const AMBIGUOUS_AUTH_CODE = 37;
const ENVIRONMENT_REJECTED_MARKERS = ['环境存在异常', '环境异常', 'abnormal environment'];
const RECRUITER_ONLY_MSG = '该命令仅支持招聘端(BOSS 端)账号,请使用招聘者账号登录后重试。';
const DEFAULT_TIMEOUT = 15_000;
// ── Core helpers ────────────────────────────────────────────────────────────
/**
 * Assert that page is available (non-null).
 */
export function requirePage(page) {
    if (!page)
        throw new CommandExecutionError('Browser page required');
}
export function readPositiveInteger(raw, name, fallback, max) {
    const value = raw === undefined || raw === null || raw === '' ? fallback : Number(raw);
    if (!Number.isInteger(value) || value < 1) {
        throw new ArgumentError(`boss ${name} must be a positive integer`);
    }
    if (max !== undefined && value > max) {
        throw new ArgumentError(`boss ${name} must be <= ${max}`);
    }
    return value;
}
export function readRequiredString(raw, name) {
    const value = String(raw ?? '').trim();
    if (!value) {
        throw new ArgumentError(`boss ${name} cannot be empty`);
    }
    return value;
}
/**
 * Navigate to BOSS chat page and wait for it to settle.
 * This establishes the cookie context needed for subsequent API calls.
 */
export async function navigateToChat(page, waitSeconds = 2) {
    await page.goto(CHAT_URL);
    await page.wait({ time: waitSeconds });
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Lower the flag value so it is <= the documented max for that option.
  2. Check the command's help output (or the call site passing `max`) for the allowed upper bound.
  3. If you need more data, paginate with multiple calls instead of raising limit.
  4. If the max seems too restrictive for a legitimate use, file an issue or patch the call site's `max` argument.

Example fix

// before
cli friends --limit 500
// after
cli friends --limit 100   # max enforced by readPositiveInteger
Defensive patterns

Strategy: validation

Validate before calling

function assertPositiveIntWithinMax(raw, name, max) {
  const v = Number(raw);
  if (!Number.isInteger(v) || v < 1) throw new Error(`${name} must be a positive integer`);
  if (max !== undefined && v > max) throw new Error(`${name} must be <= ${max}`);
  return v;
}
assertPositiveIntWithinMax(opts.limit, 'limit', 100);

Type guard

function isPositiveIntWithinMax(v, max) {
  return Number.isInteger(v) && v >= 1 && (max === undefined || v <= max);
}

Try / catch

try {
  await cli.friends({ limit });
} catch (e) {
  if (e instanceof ArgumentError && /must be <=/.test(e.message)) {
    const max = Number(e.message.match(/<= (\d+)/)?.[1] ?? 100);
    return cli.friends({ limit: max });
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling a command with a numeric flag exceeding its allowed maximum, e.g. --limit 500 when the max is 100, or --page 9999 when a bounded pageNum is enforced. The raw string is converted with Number() and compared with `value > max`.

Common situations: Typing an overly large --limit expecting 'all results'; scripting a loop that increments a page/limit flag past the documented ceiling; copy-pasting defaults from another tool with higher caps.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


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