{"record":{"id":"c79e67d20cb4df86","repo":"jackwener/OpenCLI","slug":"boss-name-must-be-max","errorCode":null,"errorMessage":"boss ${name} must be <= ${max}","messagePattern":"boss (.+?) must be <= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/boss/utils.js","lineNumber":26,"sourceCode":"const 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) {\n    await page.goto(CHAT_URL);\n    await page.wait({ time: waitSeconds });\n}","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/boss/utils.js#L8-L44","documentation":"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.","triggerScenarios":"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`.","commonSituations":"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.","solutions":["Lower the flag value so it is <= the documented max for that option.","Check the command's help output (or the call site passing `max`) for the allowed upper bound.","If you need more data, paginate with multiple calls instead of raising limit.","If the max seems too restrictive for a legitimate use, file an issue or patch the call site's `max` argument."],"exampleFix":"// before\ncli friends --limit 500\n// after\ncli friends --limit 100   # max enforced by readPositiveInteger","handlingStrategy":"validation","validationCode":"function assertPositiveIntWithinMax(raw, name, max) {\n  const v = Number(raw);\n  if (!Number.isInteger(v) || v < 1) throw new Error(`${name} must be a positive integer`);\n  if (max !== undefined && v > max) throw new Error(`${name} must be <= ${max}`);\n  return v;\n}\nassertPositiveIntWithinMax(opts.limit, 'limit', 100);","typeGuard":"function isPositiveIntWithinMax(v, max) {\n  return Number.isInteger(v) && v >= 1 && (max === undefined || v <= max);\n}","tryCatchPattern":"try {\n  await cli.friends({ limit });\n} catch (e) {\n  if (e instanceof ArgumentError && /must be <=/.test(e.message)) {\n    const max = Number(e.message.match(/<= (\\d+)/)?.[1] ?? 100);\n    return cli.friends({ limit: max });\n  }\n  throw e;\n}","preventionTips":["Clamp numeric flags to documented maxima before invoking commands","Use a CLI arg parser with min/max validators on number options","Paginate instead of raising limit to fetch more data"],"tags":["validation","cli-options","argument-error"],"backgroundTag":"invalid-cli-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}