{"record":{"id":"a4b5e46af3f46aa1","repo":"jackwener/OpenCLI","slug":"limit-must-be-max-a4b5e4","errorCode":null,"errorMessage":"limit must be <= ${max}","messagePattern":"limit must be <= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/gmail/utils.js","lineNumber":34,"sourceCode":"\nexport function unwrapBrowserResult(value, label = 'browser probe') {\n  if (value && typeof value === 'object' && !Array.isArray(value) && 'session' in value) {\n    if (typeof value.session === 'string' && Object.prototype.hasOwnProperty.call(value, 'data')) {\n      return value.data;\n    }\n    throw new CommandExecutionError(`Gmail ${label} returned a malformed Browser Bridge envelope`);\n  }\n  return value;\n}\n\nexport function parseLimit(raw, fallback = DEFAULT_LIMIT, max = MAX_LIMIT) {\n  const value = raw ?? fallback;\n  const limit = Number(value);\n  if (!Number.isInteger(limit) || limit <= 0) {\n    throw new ArgumentError('limit must be a positive integer');\n  }\n  if (limit > max) {\n    throw new ArgumentError(`limit must be <= ${max}`);\n  }\n  return limit;\n}\n\nexport function parseAccount(raw) {\n  const value = raw ?? 0;\n  const account = Number(value);\n  if (!Number.isInteger(account) || account < 0 || account > 20) {\n    throw new ArgumentError('account must be an integer between 0 and 20');\n  }\n  return account;\n}\n\nfunction cleanString(value) {\n  return typeof value === 'string' ? value.trim() : '';\n}\n\nfunction gmailDate(value, label) {","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gmail/utils.js#L16-L52","documentation":"parseLimit also enforces an upper bound: the limit may not exceed max (the command's configured maximum, e.g. 200). This protects the browser capture pipeline from oversized requests. Exceeding it throws ArgumentError with the allowed maximum in the message.","triggerScenarios":"Calling a gmail thread query with limit > max, e.g. `--limit 500` when MAX_LIMIT is 200, or a script computing a large batch size without clamping.","commonSituations":"Users assuming 'more is fine' and setting limit=1000; scripts that pass total mailbox counts as limit; callers unaware the command documented a 1-200 range.","solutions":["Reduce limit to the documented maximum (see the command's help text, e.g. 1-200).","Clamp the value in the calling code: limit = Math.min(limit, 200).","Paginate: issue multiple calls with limit=max and offset/continuation instead of one huge request."],"exampleFix":"// before\ncli --limit 1000\n// after\ncli --limit 200  // max allowed","handlingStrategy":"validation","validationCode":"const MAX_LIMIT = 200;\nconst limit = Math.min(Math.max(1, Math.trunc(Number(raw) || 20)), MAX_LIMIT);","typeGuard":null,"tryCatchPattern":"try {\n  await gmailSearch({ limit });\n} catch (e) {\n  if (e instanceof ArgumentError && /limit must be <=/.test(e.message)) {\n    const max = Number(e.message.match(/<= (\\d+)/)?.[1] ?? 200);\n    return gmailSearch({ limit: max });\n  }\n  throw e;\n}","preventionTips":["Clamp user-supplied limits to the documented range before calling.","Paginate large result sets instead of one oversized request.","Read the command's help text for the allowed limit range.","Bound computed batch sizes in automation scripts."],"tags":["validation","arguments","limits"],"backgroundTag":"invalid-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}