{"record":{"id":"bbc0259018d3f4f9","repo":"Budibase/budibase","slug":"limit-query-must-be-between-1-and-100","errorCode":null,"errorMessage":"Limit query must be between 1 and 100","messagePattern":"Limit query must be between 1 and 100","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"warning","filePath":"packages/server/src/api/controllers/ai/agentLogs.ts","lineNumber":53,"sourceCode":"    throw new HTTPError(\"Invalid bookmark query\", 400)\n  }\n\n  return String(parsedBookmark)\n}\n\nfunction sanitizeLimitQuery(limit?: string): number | undefined {\n  const normalizedLimit = limit?.trim()\n  if (!normalizedLimit) {\n    return undefined\n  }\n\n  if (!/^\\d+$/.test(normalizedLimit)) {\n    throw new HTTPError(\"Invalid limit query\", 400)\n  }\n\n  const parsedLimit = Number.parseInt(normalizedLimit, 10)\n  if (parsedLimit < 1 || parsedLimit > 100) {\n    throw new HTTPError(\"Limit query must be between 1 and 100\", 400)\n  }\n\n  return parsedLimit\n}\n\nfunction sanitizeDateQuery(\n  value: string | undefined,\n  queryName: \"startDate\" | \"endDate\"\n): string | undefined {\n  const normalizedValue = value?.trim()\n  if (!normalizedValue) {\n    return undefined\n  }\n\n  if (DATE_ONLY_REGEX.test(normalizedValue)) {\n    return normalizedValue\n  }\n","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/ai/agentLogs.ts#L35-L71","documentation":"A syntactically valid numeric limit is still rejected with HTTPError 400 if it falls outside the allowed range of 1 to 100. This bounds result page size to protect the server and clients.","triggerScenarios":"GET agent logs with ?limit=0, ?limit=101, ?limit=1000.","commonSituations":"Client clamping to its own max (e.g. 500) instead of the API's 100; sending 0 to mean \"default\".","solutions":["Clamp the limit to 1–100 on the client before sending","Send no limit to accept the server default","Update integrations that assumed larger page sizes"],"exampleFix":"// before\nconst limit = Math.max(0, desired) // may send 0 or >100\n// after\nconst limit = Math.min(100, Math.max(1, desired))","handlingStrategy":"validation","validationCode":"const n = parseInt(rawLimit, 10); const safeLimit = Math.min(100, Math.max(1, n))","typeGuard":"const isValidLimitRange = (n: number): boolean => Number.isInteger(n) && n >= 1 && n <= 100","tryCatchPattern":"try { await api.fetchAgentLogs({ limit }) } catch (e) { if (e.status === 400 && e.message.includes(\"between 1 and 100\")) { /* clamp and retry once */ } else throw e }","preventionTips":["Clamp limit to 1–100 client-side","Centralize the limit constant shared by client and server","Add tests covering boundary values 0, 1, 100, 101"],"tags":["validation","pagination","http-400"],"backgroundTag":"invalid-query-parameter","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}