{"record":{"id":"ee3a52e935ce2191","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-between-1-and-max","errorCode":null,"errorMessage":"limit must be an integer between 1 and ${max}","messagePattern":"limit must be an integer between 1 and (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/autohome/utils.js","lineNumber":101,"sourceCode":"export function normalizeSeriesId(rawInput) {\n    const raw = String(rawInput || '').trim();\n    if (!raw) throw new ArgumentError('series_id must be a non-empty value');\n    const m = raw.match(/\\/(?:s)?(\\d+)(?:\\/|$|\\.)/) || raw.match(/^s?(\\d+)$/);\n    if (!m) {\n        throw new ArgumentError(`'${rawInput}' does not look like an autohome series id (a number, or a k.autohome.com.cn/<id> URL)`);\n    }\n    return m[1];\n}\n\nexport function clean(s) {\n    return String(s == null ? '' : s).replace(/\\s+/g, ' ').trim();\n}\n\nexport function requireLimit(value, def, max) {\n    const raw = value == null || value === '' ? def : value;\n    const n = typeof raw === 'number' ? raw : Number(String(raw).trim());\n    if (!Number.isInteger(n) || n < 1 || n > max) {\n        throw new ArgumentError(`limit must be an integer between 1 and ${max}`);\n    }\n    return n;\n}\n\nexport function requireStableId(value, label) {\n    const id = String(value ?? '').trim();\n    if (!/^\\d+$/.test(id)) throw new CommandExecutionError(`${label} did not include a stable numeric id.`);\n    return id;\n}\n\nexport function requireText(value, label) {\n    const text = clean(value);\n    if (!text) throw new CommandExecutionError(`${label} did not include a stable text value.`);\n    return text;\n}\n\nexport function assertPlainObject(value, label) {\n    if (!value || typeof value !== 'object' || Array.isArray(value)) {","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/autohome/utils.js#L83-L119","documentation":"requireLimit() validates that a limit is an integer within 1..max (or supplies the default when null/empty). It throws this ArgumentError when the provided value is not an integer in that range — including non-numeric strings, floats, zero, or negatives.","triggerScenarios":"limit('abc'), limit(0), limit(-5), limit(2.5), or limit(max+1) on any command that accepts a --limit/limit option.","commonSituations":"CLI flag typoed (e.g. --limit=1O with letter O); parsing a string with units like '20 items'; off-by-one or unbounded upstream values exceeding the configured max.","solutions":["Pass a positive integer between 1 and max (see the command's help for max)","Omit the limit to use the default","Coerce/validate the value yourself before calling, e.g. Number() plus Number.isInteger and range check"],"exampleFix":"// before\nlimit('20 items')\n// after\nlimit(20)","handlingStrategy":"validation","validationCode":"function isValidLimit(v, max) {\n  const n = typeof v === 'number' ? v : Number(String(v ?? '').trim());\n  return Number.isInteger(n) && n >= 1 && n <= max;\n}\nif (!isValidLimit(raw, 100)) throw new Error('limit must be an integer 1..100');","typeGuard":null,"tryCatchPattern":"try {\n  await cmd({ limit });\n} catch (err) {\n  if (err instanceof ArgumentError && /limit must be an integer/.test(err.message)) {\n    console.error('Pass --limit as an integer between 1 and the command max');\n  } else throw err;\n}","preventionTips":["Sanitize numeric CLI flags with Number() before passing","Reject float/NaN values at your CLI parsing layer","Document the allowed limit range in your tool's help text"],"tags":["validation","argument-error","range-check"],"backgroundTag":"invalid-parameter-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}