{"record":{"id":"4951016c595700c1","repo":"jackwener/OpenCLI","slug":"nowcoder-name-must-be-an-integer-from-1-to","errorCode":null,"errorMessage":"nowcoder --${name} must be an integer from 1 to ${maximum}","messagePattern":"nowcoder --(.+?) must be an integer from 1 to (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/nowcoder/posts.js","lineNumber":234,"sourceCode":"        uuid,\n        entity_id: entityId,\n        url: isContent\n            ? `https://www.nowcoder.com/discuss/${id}`\n            : `https://www.nowcoder.com/feed/main/detail/${uuid}`,\n        title: optionalText(data.title, `${target.post_type} title`) || '(untitled)',\n        ...authorFields(data.userBrief, expectedAuthorId, target.post_type),\n        content: body,\n        likes: metric(data.frequencyData, 'likeCnt'),\n        comments: metric(data.frequencyData, 'commentCnt'),\n        views: metric(data.frequencyData, 'viewCnt'),\n        time: isoTime(isContent ? data.createTime : data.createdAt, `${target.post_type} timestamp`),\n        location: optionalText(data.ip4Location, `${target.post_type} location`),\n    };\n}\n\nexport function requirePositiveInt(value, name, maximum) {\n    const number = Number(value);\n    if (!Number.isInteger(number) || number < 1 || number > maximum) throw new ArgumentError(`nowcoder --${name} must be an integer from 1 to ${maximum}`);\n    return number;\n}\n\nexport async function fetchNowcoderData(page, url, options, label) {\n    let payload;\n    try {\n        await page.goto('https://www.nowcoder.com');\n        payload = await page.fetchJson(url, options);\n    }\n    catch (error) {\n        const detail = String(error?.message ?? error);\n        if (/HTTP\\s+(401|403)|need login|not logged in/i.test(detail)) {\n            throw new AuthRequiredError('nowcoder.com', `${label} requires a logged-in Nowcoder session`);\n        }\n        throw new CommandExecutionError(`${label} failed: ${detail}`);\n    }\n    if (!isRecord(payload) || typeof payload.success !== 'boolean' || !Number.isSafeInteger(payload.code)) throw new CommandExecutionError(`${label} returned a malformed envelope`);\n    const message = typeof payload.msg === 'string' ? payload.msg : 'unknown error';","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/nowcoder/posts.js#L216-L252","documentation":"requirePositiveInt validates CLI option values such as --page-number and --limit. The value must be an integer (after Number coercion) between 1 and the provided maximum inclusive. Non-integers, values below 1, values above the cap, or non-numeric strings throw this ArgumentError naming the offending flag and its valid range.","triggerScenarios":"Running nowcoder commands with --limit 0, --limit 200 when the max is lower, --page-number abc, --limit 10.5, or empty/whitespace values for these flags.","commonSituations":"Copy-pasting '--limit ' with a trailing value lost in shell quoting; assuming pagination starts at 0; trying to fetch more results per page than the CLI's configured maximum; using float or scientific notation values.","solutions":["Pass an integer >= 1 and <= the documented maximum, e.g. --limit 50 --page-number 1.","Check the CLI help output (nowcoder --help) for the exact per-flag maximum.","Quote values carefully in your shell so the flag value isn't dropped or mangled.","To page through more results, increment --page-number instead of raising --limit beyond the cap."],"exampleFix":"// before\nnowcoder posts list --limit 0\nnowcoder posts list --limit \"\"\n// after\nnowcoder posts list --limit 20 --page-number 1","handlingStrategy":"validation","validationCode":"function validatePositiveInt(value, name, max) {\n  const n = Number(value);\n  if (!Number.isInteger(n) || n < 1 || n > max) {\n    throw new RangeError(`--${name} must be an integer from 1 to ${max}, got ${JSON.stringify(value)}`);\n  }\n  return n;\n}\n// validatePositiveInt(process.env.LIMIT, 'limit', 100) before invoking the CLI","typeGuard":"function isValidPageOption(value, max = 100) {\n  const n = Number(value);\n  return Number.isInteger(n) && n >= 1 && n <= max;\n}","tryCatchPattern":"try {\n  await nowcoderPostsList({ limit, pageNumber });\n} catch (err) {\n  if (err instanceof ArgumentError && /must be an integer from 1 to/.test(err.message)) {\n    console.error(err.message); process.exitCode = 2;\n  } else throw err;\n}","preventionTips":["Always pass page-number >= 1 (pagination is 1-based).","Clamp limit to the documented maximum in wrapper scripts.","Quote flag values in shell to avoid empty/mangled values.","Use the CLI help to check each flag's valid range before scripting."],"tags":["argument-validation","cli-input","input-validation"],"backgroundTag":"invalid-cli-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}