{"record":{"id":"48234bb2627ea3c9","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-between-1-and-20","errorCode":null,"errorMessage":"--limit must be an integer between 1 and 20","messagePattern":"--limit must be an integer between 1 and 20","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/trae-cn/utils.js","lineNumber":95,"sourceCode":"      expanded.push('terminal', 'delete', 'keep');\n      continue;\n    }\n    if (!['terminal', 'delete', 'keep'].includes(item)) {\n      throw new ArgumentError('--approve-kinds must contain only terminal, delete, keep, or all');\n    }\n    expanded.push(item);\n  }\n  const unique = Array.from(new Set(expanded));\n  if (unique.length === 0) {\n    throw new ArgumentError('--approve-kinds must contain at least one approval kind');\n  }\n  return unique;\n}\n\nexport function normalizeApprovalLimit(value, fallback = 1) {\n  const limit = value === undefined || value === null ? fallback : Number(value);\n  if (!Number.isInteger(limit) || limit < 1 || limit > 20) {\n    throw new ArgumentError('--limit must be an integer between 1 and 20');\n  }\n  return limit;\n}\n\nexport function ensurePrompt(text) {\n  const prompt = typeof text === 'string' ? text : '';\n  if (!prompt.trim()) {\n    throw new ArgumentError('text must not be empty');\n  }\n  return prompt;\n}\n\nexport function normalizeModelLabel(text) {\n  return String(text || '').toLowerCase().replace(/[^a-z0-9.]+/g, '');\n}\n\nexport function listOpenModelItemsScript() {\n  return `","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trae-cn/utils.js#L77-L113","documentation":"normalizeApprovalLimit coerces the --limit value with Number() and requires an integer in the inclusive range 1..20. Non-numeric strings, decimals, zero, negatives, and values above 20 all throw this ArgumentError.","triggerScenarios":"--limit 0, --limit 25, --limit 2.5, --limit 'many', or --limit with whitespace-only text from a config value.","commonSituations":"Users assuming the limit is unbounded, or scripts interpolating empty/unset variables into the flag.","solutions":["Pass an integer from 1 to 20, e.g. --limit 5","Quote/validate the value in shell scripts before interpolation","Check for stray units like '5x' or '5 ' in config files"],"exampleFix":"// before\n--limit 50\n// after\n--limit 20","handlingStrategy":"validation","validationCode":"function isValidLimit(v, fallback = 1) {\n  if (v === undefined || v === null) return true;\n  const n = Number(v);\n  return Number.isInteger(n) && n >= 1 && n <= 20;\n}","typeGuard":"const isValidLimit = (v) => Number.isInteger(Number(v)) && Number(v) >= 1 && Number(v) <= 20;","tryCatchPattern":"try { limit = normalizeApprovalLimit(raw); } catch (e) { if (e instanceof ArgumentError) { console.error('Use --limit as an integer 1-20'); process.exitCode = 2; } else throw e; }","preventionTips":["Clamp user-provided limits into [1,20] before passing","Reject non-numeric config values at config-load time","Watch for empty strings from unset env vars becoming NaN"],"tags":["cli","argument-validation","range-check"],"backgroundTag":"invalid-cli-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}