{"record":{"id":"e222dfbb24a2ae19","repo":"jackwener/OpenCLI","slug":"juejin-label-must-be-a-positive-decimal-integer","errorCode":null,"errorMessage":"juejin ${label} must be a positive decimal integer","messagePattern":"juejin (.+?) must be a positive decimal integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/juejin/utils.js","lineNumber":44,"sourceCode":"export function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) {\n        throw new ArgumentError(`juejin ${label} cannot be empty`);\n    }\n    return s;\n}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\n    const raw = value ?? defaultValue;\n    let n;\n    if (typeof raw === 'number') {\n        n = raw;\n    }\n    else if (typeof raw === 'string' && /^[1-9]\\d*$/.test(raw)) {\n        n = Number(raw);\n    }\n    else {\n        throw new ArgumentError(`juejin ${label} must be a positive decimal integer`);\n    }\n    if (!Number.isSafeInteger(n) || n <= 0) {\n        throw new ArgumentError(`juejin ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`juejin ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport function requireCursor(value) {\n    const raw = value ?? '0';\n    if (typeof raw === 'number') {\n        if (Number.isSafeInteger(raw) && raw >= 0) return String(raw);\n        throw new ArgumentError('juejin cursor must be a non-negative decimal integer');\n    }\n    if (typeof raw === 'string' && /^(0|[1-9]\\d*)$/.test(raw)) {\n        return raw;","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/juejin/utils.js#L26-L62","documentation":"requireBoundedInt validates numeric limit-like arguments. A value is accepted if it is a number or a string matching /^[1-9]\\d*$/ (positive decimal integer without leading zeros). Anything else — floats, negatives, zero, hex/octal/underscored numbers, strings with signs or whitespace-only digits — triggers this ArgumentError before further range checks.","triggerScenarios":"Passing e.g. --limit 1.5, --limit -3, --limit 0x10, --limit \"12 \", --limit +5, --limit 007, or a non-numeric string like --limit ten to any command whose limit option calls requireBoundedInt.","commonSituations":"Copy-pasting numbers with invisible whitespace or thousands separators (1,000); using a float from a config file; scripting with bc/awk output like '2.0'; locale-formatted numbers.","solutions":["Pass a plain positive integer: --limit 20.","Sanitize the value before invoking: strip commas/whitespace, round floats with Math.floor.","If the value comes from config/env, validate with /^[1-9]\\d*$/.test(String(v).trim()) first.","Use the default by omitting the option if a custom limit is not needed."],"exampleFix":"// before\nconst n = parseFloat(input); // 2.5 -> throws downstream\ncli({ limit: String(n) });\n// after\nconst n = parseInt(input, 10);\nif (!/^[1-9]\\d*$/.test(String(n))) throw new Error('bad limit');\ncli({ limit: String(n) });","handlingStrategy":"validation","validationCode":"function toPositiveInt(v){ const s = String(v ?? '').trim().replace(/[,\\s_]/g, ''); if (!/^[1-9]\\d*$/.test(s)) throw new Error('limit must be a positive decimal integer'); return Number(s); }\n// const limit = toPositiveInt(opts.limit);","typeGuard":"function isPositiveDecimalIntString(v){ return typeof v === 'string' && /^[1-9]\\d*$/.test(v) || (typeof v === 'number' && Number.isInteger(v) && v > 0); }","tryCatchPattern":"try {\n  cli({ limit });\n} catch (e) {\n  if (/must be a positive decimal integer/.test(e.message)) {\n    cli({ limit: 20 }); // fall back to default page size\n  } else throw e;\n}","preventionTips":["Never pass user-typed limit strings directly; normalize (strip separators, parseInt radix 10) first.","Reject floats, negatives, and leading-zero forms at the input boundary.","Prefer omitting the option to use the library default when unsure.","Add a regex pre-check /^[1-9]\\d*$/ in shell wrappers."],"tags":["argument-validation","cli","input-validation","integer"],"backgroundTag":"invalid-numeric-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}