{"record":{"id":"8c81bab7b98df948","repo":"jackwener/OpenCLI","slug":"weibo-user-posts-limit-must-be-an-integer-between","errorCode":null,"errorMessage":"weibo user-posts limit must be an integer between 1 and ${MAX_LIMIT}","messagePattern":"weibo user-posts limit must be an integer between 1 and (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/weibo/user-posts.js","lineNumber":23,"sourceCode":"import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { unwrapEvaluateResult } from './utils.js';\n\nconst MAX_LIMIT = 100;\nconst DEFAULT_LIMIT = 20;\nconst DATE_RE = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nfunction readRequiredId(raw) {\n    const value = String(raw ?? '').trim();\n    if (!value) {\n        throw new ArgumentError('weibo user-posts id cannot be empty');\n    }\n    return value;\n}\n\nfunction readLimit(raw) {\n    const value = raw === undefined || raw === null || raw === '' ? DEFAULT_LIMIT : Number(raw);\n    if (!Number.isInteger(value) || value < 1 || value > MAX_LIMIT) {\n        throw new ArgumentError(`weibo user-posts limit must be an integer between 1 and ${MAX_LIMIT}`);\n    }\n    return value;\n}\n\nfunction readDate(raw, name) {\n    if (raw === undefined || raw === null || raw === '') return null;\n    const value = String(raw).trim();\n    if (!DATE_RE.test(value)) {\n        throw new ArgumentError(`weibo user-posts ${name} must use YYYY-MM-DD`);\n    }\n    const date = new Date(`${value}T00:00:00+08:00`);\n    if (!Number.isFinite(date.getTime()) || value !== formatShanghaiDate(date)) {\n        throw new ArgumentError(`weibo user-posts ${name} must be a valid calendar date`);\n    }\n    return value;\n}\n\nfunction formatShanghaiDate(date) {","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/user-posts.js#L5-L41","documentation":"ArgumentError thrown by readLimit when the `limit` option is not an integer in [1, MAX_LIMIT] (MAX_LIMIT = 100). Empty/absent values default to 20; anything else must parse via Number() into a whole number within range. Note the thrown message interpolates MAX_LIMIT at runtime despite the literal string shown.","triggerScenarios":"Passing `--limit 0`, `--limit 101`, `--limit abc`, `--limit 12.5`, or any non-numeric string to `weibo user-posts`.","commonSituations":"Copy-pasting a limit with a trailing space/unit ('20 条'); passing a float or comma-formatted number ('1,000'); setting limit from a config/env var containing garbage; assuming the cap is higher than 100.","solutions":["Pass an integer between 1 and 100, e.g. `--limit 50`","Strip whitespace/units and validate numeric config values before invoking","Omit --limit entirely to use the default of 20"],"exampleFix":"// before\nweibo user-posts 12345 --limit \"1,000\"\n// after\nweibo user-posts 12345 --limit 100","handlingStrategy":"validation","validationCode":"const limit = Number(rawLimit);\nif (!Number.isInteger(limit) || limit < 1 || limit > 100) {\n    throw new Error('limit must be an integer between 1 and 100');\n}\nawait weiboUserPosts({ id, limit });","typeGuard":"function isValidLimit(v) {\n    return Number.isInteger(v) && v >= 1 && v <= 100;\n}","tryCatchPattern":"try {\n    await weiboUserPosts({ id, limit });\n} catch (err) {\n    if (err instanceof ArgumentError && String(err.message).includes('limit')) {\n        console.error('Pass an integer between 1 and 100, or omit --limit for the default of 20.');\n    } else throw err;\n}","preventionTips":["Validate/parse limit from config or env before passing it to the CLI","Strip units, whitespace, and thousands separators from user-supplied numbers","Remember the max is 100; omit the option for the default of 20"],"tags":["argument-validation","range-validation","cli"],"backgroundTag":"argument-out-of-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}