jackwener/OpenCLI · error · ArgumentError
boss ${name} must be a positive integer
Error message
boss ${name} must be a positive integer What it means
readPositiveInteger normalizes numeric arguments (limit, pageNum, currentPage, etc.) for boss commands. If the raw value is not an integer >= 1 (or exceeds the optional max), it throws this ArgumentError naming the parameter, e.g. 'boss limit must be a positive integer'.
Source
Thrown at clis/boss/utils.js:23
const CHAT_URL = `https://${BOSS_DOMAIN}/web/chat/index`;
const COOKIE_EXPIRED_CODES = new Set([7, 37]);
const COOKIE_EXPIRED_MSG = 'Cookie 已过期!请在当前 Chrome 浏览器中重新登录 BOSS 直聘。';
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) {View on GitHub (pinned to 49907e53dc)
Solutions
- Pass whole numbers >= 1 for limit/pageNum/currentPage
- Use 1-based page numbering (first page is 1, not 0)
- Clamp values to the command's documented max before calling
- Coerce/validate user or config input with Number.isInteger before passing
- Fix off-by-one or float math in pagination loops (use Math.floor / integer counters)
Example fix
// before
await cli('boss', 'search', { query: 'go', limit: 'all' });
// after
const limit = Number.parseInt(userInput, 10);
if (!Number.isInteger(limit) || limit < 1) throw new Error('limit must be >= 1');
await cli('boss', 'search', { query: 'go', limit: Math.min(limit, 10) }); Defensive patterns
Strategy: validation
Validate before calling
function toPositiveInt(v, fallback) {
if (v === undefined || v === null || v === '') return fallback;
const n = Number(v);
return Number.isInteger(n) && n >= 1 ? n : null;
}
const limit = toPositiveInt(rawLimit, 10);
if (limit === null) throw new Error('limit must be a positive integer'); Type guard
const isPositiveInt = (v) => typeof v === 'number' && Number.isInteger(v) && v >= 1;
Try / catch
try {
return await cli('boss', 'search', { limit: raw });
} catch (e) {
if (String(e.message).includes('must be a positive integer')) {
return cli('boss', 'search', { limit: 10 }); // sane default
}
throw e;
} Prevention
- Coerce and clamp numeric CLI/config input before calling
- Remember pages are 1-based
- Use integer math in pagination loops
- Document accepted ranges (min 1, command-specific max)
When it happens
Trigger: Passing limit=0, limit=-1, limit='all', pageNum='2.5', or a value above the command's max (e.g. pageNum > allowed pages) to boss search/send/resume options.
Common situations: CLI users passing non-numeric strings ('all', '10+'); floats from config files; 0-based vs 1-based page numbering confusion; off-by-one pagination loops exceeding max.
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
- Invalid BOSS city: ${input}
- coingecko limit must be <= 250 (per_page upper bound)
- coingecko page must be a positive integer
- --page must be a positive integer (got ${raw})
- --offset must be a multiple of 10 for DuckDuckGo HTML pagina
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/1da20b8b040c8f08.
Report an issue: GitHub.