{"record":{"id":"464ecec3b81f63a3","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-between-1-and-200","errorCode":null,"errorMessage":"--limit must be an integer between 1 and 200","messagePattern":"--limit must be an integer between 1 and 200","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/trae-cn/utils.js","lineNumber":40,"sourceCode":"  'Set-Content',\n  'Out-File',\n  'mkfs',\n  'git force/delete/hard/filter/rebase operations',\n  'destructive database commands',\n];\n\nexport function normalizeTimeout(value, fallback = 60) {\n  const timeout = value === undefined || value === null ? fallback : Number(value);\n  if (!Number.isInteger(timeout) || timeout < 1) {\n    throw new ArgumentError('--timeout must be a positive integer (seconds)');\n  }\n  return timeout;\n}\n\nexport function normalizeLimit(value, fallback = 20) {\n  const limit = value === undefined || value === null ? fallback : Number(value);\n  if (!Number.isInteger(limit) || limit < 1 || limit > 200) {\n    throw new ArgumentError('--limit must be an integer between 1 and 200');\n  }\n  return limit;\n}\n\nexport function normalizeMaxChars(value, fallback = 6000) {\n  const maxChars = value === undefined || value === null ? fallback : Number(value);\n  if (!Number.isInteger(maxChars) || maxChars < 0 || maxChars > 1_000_000) {\n    throw new ArgumentError('--max-chars must be an integer between 0 and 1000000');\n  }\n  return maxChars;\n}\n\nexport function normalizeDuration(value, fallback = 30) {\n  const duration = value === undefined || value === null ? fallback : Number(value);\n  if (!Number.isInteger(duration) || duration < 1 || duration > 3600) {\n    throw new ArgumentError('--duration must be an integer between 1 and 3600 seconds');\n  }\n  return duration;","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trae-cn/utils.js#L22-L58","documentation":"normalizeLimit in utils.js throws an ArgumentError when the --limit value is not an integer in the inclusive range 1-200. The limit caps how many activity items are returned; values outside the band (including NaN from non-numeric input) are rejected.","triggerScenarios":"Running a command with `--limit 0`, `--limit 201`, `--limit -1`, `--limit 10.5`, or non-numeric strings like `--limit all`.","commonSituations":"Trying to fetch 'everything' with --limit 0 or a huge number like 99999; unit tests hardcoding boundary values; scripts passing empty variables (Number('') === 0).","solutions":["Pass an integer between 1 and 200, e.g. --limit 50.","Omit --limit to use the default of 20.","Clamp large values to 200 in your script before passing.","Guard against empty variables: --limit \"${LIMIT:-20}\"."],"exampleFix":"// before\nopencli trae-cn activity --limit 500\n// after\nopencli trae-cn activity --limit 200","handlingStrategy":"validation","validationCode":"function assertLimit(v, fallback = 20) {\n  const n = v === undefined || v === null ? fallback : Number(v);\n  if (!Number.isInteger(n) || n < 1 || n > 200) throw new Error(`Invalid --limit: ${JSON.stringify(v)}; must be an integer 1-200`);\n  return n;\n}","typeGuard":"function isValidLimit(v) {\n  return v === undefined || v === null ||\n    (Number.isInteger(Number(v)) && Number(v) >= 1 && Number(v) <= 200);\n}","tryCatchPattern":"try {\n  return await listActivities(limit);\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.includes('--limit')) {\n    return listActivities(Math.min(Math.max(Number(limit) || 20, 1), 200));\n  }\n  throw e;\n}","preventionTips":["Clamp requested limits to [1, 200] before passing.","Never use 0 or huge values to mean 'all' — use the max 200.","Default to omitting --limit when the default 20 suffices.","Guard empty shell variables with ${LIMIT:-20}."],"tags":["argument-validation","cli","input-validation"],"backgroundTag":"invalid-cli-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}