{"record":{"id":"3000e5172d7ac56d","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-between-1-and-max-g","errorCode":null,"errorMessage":"--limit must be an integer between 1 and ${max} (got ${raw})","messagePattern":"--limit must be an integer between 1 and (.+?) \\(got (.+?)\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/coupang/utils.js","lineNumber":18,"sourceCode":"import { ArgumentError } from '@jackwener/opencli/errors';\n\n/**\n * Parse a positive integer arg (--limit / --page / --review-page).\n *\n * Throws ArgumentError on out-of-range / non-integer values rather than\n * silently clamping. We prefer typed-fail-fast over silent clamping for the\n * same reason as feedback_typed_fail_fast_for_adapters: callers cannot tell\n * that their value was rewritten and end up confused why \"limit=999\" returned\n * 50 rows.\n */\nexport function parseLimitArg(raw, fallback, max) {\n    if (raw === undefined || raw === null || raw === '') {\n        return fallback;\n    }\n    const num = Number(raw);\n    if (!Number.isInteger(num) || num < 1 || num > max) {\n        throw new ArgumentError(`--limit must be an integer between 1 and ${max} (got ${raw})`);\n    }\n    return num;\n}\n\nexport function parsePageArg(raw, fallback) {\n    if (raw === undefined || raw === null || raw === '') {\n        return fallback;\n    }\n    const num = Number(raw);\n    if (!Number.isInteger(num) || num < 1) {\n        throw new ArgumentError(`--page must be a positive integer (got ${raw})`);\n    }\n    return num;\n}\n\nfunction itemKey(item) {\n    return item.url || item.product_id || `${item.title}:${item.price ?? ''}`;\n}","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/coupang/utils.js#L1-L36","documentation":"ArgumentError thrown by parseLimitArg when --limit is provided but is not an integer within [1, max]. The CLI deliberately fails fast instead of clamping, so callers see the exact invalid value.","triggerScenarios":"Passing --limit as a non-integer (e.g. 2.5), zero, negative, a non-numeric string ('many'), or a value above the command's max (e.g. --limit 999 when max is 50).","commonSituations":"Copy-pasting a limit from another tool with a different range; typo like `--limit=0`; scripting with an unset variable expanding to an empty/garbage string (empty string is OK — falls back — but whitespace is not).","solutions":["Pass an integer between 1 and the max shown in the error","Omit --limit entirely to use the fallback","Clamp/validate your own input before invoking the CLI","Check for stray whitespace or units in the value (e.g. '50 items')"],"exampleFix":"// before\n--limit 999\n// after\n--limit 50","handlingStrategy":"validation","validationCode":"function validLimit(raw, max) { const n = Number(raw); return Number.isInteger(n) && n >= 1 && n <= max ? n : null; }","typeGuard":"function isValidLimit(v, max) { return typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= max; }","tryCatchPattern":"try { await cli.run(['coupang','search', q, '--limit', String(limit)]); } catch (e) { if (e instanceof ArgumentError && e.message.startsWith('--limit')) { limit = 20; return retry(); } throw e; }","preventionTips":["Always pass integers within the command's documented max","Omit --limit when the default is acceptable","Clamp user input before shelling out to the CLI"],"tags":["argument-validation","cli"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}