{"record":{"id":"1da20b8b040c8f08","repo":"jackwener/OpenCLI","slug":"boss-name-must-be-a-positive-integer","errorCode":null,"errorMessage":"boss ${name} must be a positive integer","messagePattern":"boss (.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/boss/utils.js","lineNumber":23,"sourceCode":"const CHAT_URL = `https://${BOSS_DOMAIN}/web/chat/index`;\nconst COOKIE_EXPIRED_CODES = new Set([7, 37]);\nconst COOKIE_EXPIRED_MSG = 'Cookie 已过期！请在当前 Chrome 浏览器中重新登录 BOSS 直聘。';\nconst AMBIGUOUS_AUTH_CODE = 37;\nconst ENVIRONMENT_REJECTED_MARKERS = ['环境存在异常', '环境异常', 'abnormal environment'];\nconst RECRUITER_ONLY_MSG = '该命令仅支持招聘端（BOSS 端）账号，请使用招聘者账号登录后重试。';\nconst DEFAULT_TIMEOUT = 15_000;\n// ── Core helpers ────────────────────────────────────────────────────────────\n/**\n * Assert that page is available (non-null).\n */\nexport function requirePage(page) {\n    if (!page)\n        throw new CommandExecutionError('Browser page required');\n}\nexport function readPositiveInteger(raw, name, fallback, max) {\n    const value = raw === undefined || raw === null || raw === '' ? fallback : Number(raw);\n    if (!Number.isInteger(value) || value < 1) {\n        throw new ArgumentError(`boss ${name} must be a positive integer`);\n    }\n    if (max !== undefined && value > max) {\n        throw new ArgumentError(`boss ${name} must be <= ${max}`);\n    }\n    return value;\n}\nexport function readRequiredString(raw, name) {\n    const value = String(raw ?? '').trim();\n    if (!value) {\n        throw new ArgumentError(`boss ${name} cannot be empty`);\n    }\n    return value;\n}\n/**\n * Navigate to BOSS chat page and wait for it to settle.\n * This establishes the cookie context needed for subsequent API calls.\n */\nexport async function navigateToChat(page, waitSeconds = 2) {","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/boss/utils.js#L5-L41","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"// before\nawait cli('boss', 'search', { query: 'go', limit: 'all' });\n// after\nconst limit = Number.parseInt(userInput, 10);\nif (!Number.isInteger(limit) || limit < 1) throw new Error('limit must be >= 1');\nawait cli('boss', 'search', { query: 'go', limit: Math.min(limit, 10) });","handlingStrategy":"validation","validationCode":"function toPositiveInt(v, fallback) {\n  if (v === undefined || v === null || v === '') return fallback;\n  const n = Number(v);\n  return Number.isInteger(n) && n >= 1 ? n : null;\n}\nconst limit = toPositiveInt(rawLimit, 10);\nif (limit === null) throw new Error('limit must be a positive integer');","typeGuard":"const isPositiveInt = (v) => typeof v === 'number' && Number.isInteger(v) && v >= 1;","tryCatchPattern":"try {\n  return await cli('boss', 'search', { limit: raw });\n} catch (e) {\n  if (String(e.message).includes('must be a positive integer')) {\n    return cli('boss', 'search', { limit: 10 }); // sane default\n  }\n  throw e;\n}","preventionTips":["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)"],"tags":["argument-validation","pagination","input-mapping"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}