{"record":{"id":"f9c8ad3242428008","repo":"jackwener/OpenCLI","slug":"name-must-be-a-positive-integer-got-json-s","errorCode":null,"errorMessage":"--${name} must be a positive integer, got ${JSON.stringify(raw)}","messagePattern":"--(.+?) must be a positive integer, got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/ctrip/utils.js","lineNumber":21,"sourceCode":" *\n * The single backing endpoint `https://m.ctrip.com/restapi/soa2/21881/json/gaHotelSearchEngine`\n * accepts a `searchType` discriminator:\n *   - `D` → destination suggest (cities, scenic spots, railway stations, landmarks)\n *   - `H` → hotel-context suggest (cities, business areas, individual hotels)\n *\n * Response shape is identical; we surface every field the endpoint emits as a\n * stable column so callers do not silently lose geo / English / id metadata.\n */\nimport { ArgumentError, CliError } from '@jackwener/opencli/errors';\n\nconst ENDPOINT = 'https://m.ctrip.com/restapi/soa2/21881/json/gaHotelSearchEngine';\nconst MIN_LIMIT = 1;\nconst MAX_LIMIT = 50;\n\nfunction parseStrictDecimalInteger(name, raw) {\n    if (typeof raw === 'number') {\n        if (Number.isInteger(raw)) return raw;\n        throw new ArgumentError(`--${name} must be a positive integer, got ${JSON.stringify(raw)}`);\n    }\n    if (typeof raw === 'string' && /^(0|[1-9]\\d*)$/.test(raw)) {\n        return Number(raw);\n    }\n    throw new ArgumentError(`--${name} must be a positive integer, got ${JSON.stringify(raw)}`);\n}\n\nexport function parseStrictPositiveInteger(name, raw) {\n    const parsed = parseStrictDecimalInteger(name, raw);\n    if (parsed > 0) return parsed;\n    throw new ArgumentError(`--${name} must be a positive integer, got ${JSON.stringify(raw)}`);\n}\n\nexport function parseStrictIntegerRange(name, raw, fallback, min = MIN_LIMIT, max = MAX_LIMIT) {\n    if (raw === undefined || raw === null || raw === '') return fallback;\n    const parsed = parseStrictDecimalInteger(name, raw);\n    if (parsed < min || parsed > max) {\n        throw new ArgumentError(`--${name} must be between ${min} and ${max}, got ${parsed}`);","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/ctrip/utils.js#L3-L39","documentation":"Thrown by parseStrictDecimalInteger in clis/ctrip/utils.js when a numeric option is neither an integer number nor a string of strict decimal digits. The library only accepts non-negative integers written without signs, decimals, or exponent notation, and rejects anything else with an ArgumentError quoting the raw value via JSON.stringify.","triggerScenarios":"Passing --limit 2.5, --limit '1e2', --limit '-3', --limit '+5', --limit 'abc', or --limit ' 5 ' (whitespace) to any option routed through this parser.","commonSituations":"Shell variables containing floats or empty strings; users typing decimal limits; copy-pasted values with hidden whitespace or thousands separators like '1,000'.","solutions":["Pass a plain non-negative integer, e.g. --limit 20.","Strip whitespace and separators before passing programmatic values.","Validate numeric CLI input in your wrapper script before invoking the command."],"exampleFix":"// before\nawait run({ limit: '1,000' });\n// after\nawait run({ limit: '50' });","handlingStrategy":"validation","validationCode":"function isValidCount(v){ return typeof v === 'number' ? Number.isInteger(v) : typeof v === 'string' && /^(0|[1-9]\\d*)$/.test(v); }","typeGuard":"const isStrictDecimalInt = (v) => (typeof v === 'number' && Number.isInteger(v)) || (typeof v === 'string' && /^(0|[1-9]\\d*)$/.test(v));","tryCatchPattern":"try { await run(opts); } catch (e) { if (e instanceof ArgumentError && /positive integer/.test(e.message)) { console.error('Bad numeric flag:', e.message); } else throw e; }","preventionTips":["Pass plain integers for numeric flags","Strip whitespace/thousands separators before passing values","Never pass floats or exponent strings to limit-style options"],"tags":["argument-validation","cli","parsing"],"backgroundTag":"invalid-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}