{"record":{"id":"4321bdcd90324d0c","repo":"Budibase/budibase","slug":"page-query-must-be-greater-than-0","errorCode":null,"errorMessage":"Page query must be greater than 0","messagePattern":"Page query must be greater than 0","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/api/controllers/ai/agentRequests.ts","lineNumber":42,"sourceCode":"    throw new HTTPError(\"Limit query must be between 1 and 100\", 400)\n  }\n\n  return parsedLimit\n}\n\nconst sanitizePageQuery = (page?: string): number => {\n  const normalizedPage = page?.trim()\n  if (!normalizedPage) {\n    return 1\n  }\n\n  if (!/^\\d+$/.test(normalizedPage)) {\n    throw new HTTPError(\"Invalid page query\", 400)\n  }\n\n  const parsedPage = Number.parseInt(normalizedPage, 10)\n  if (parsedPage < 1) {\n    throw new HTTPError(\"Page query must be greater than 0\", 400)\n  }\n\n  return parsedPage\n}\n\nconst sanitizeStatusQuery = (\n  status?: string\n): AgentRequestStatus | undefined => {\n  const normalizedStatus = status?.trim()\n  if (!normalizedStatus) {\n    return undefined\n  }\n\n  if (\n    !AGENT_REQUEST_STATUSES.includes(normalizedStatus as AgentRequestStatus)\n  ) {\n    throw new HTTPError(\"Invalid status query\", 400)\n  }","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/ai/agentRequests.ts#L24-L60","documentation":"Thrown by sanitizePageQuery when the page value is numeric but less than 1. Pages are 1-indexed; ?page=0 (or a negative digit string is impossible here since '-' fails the regex, but 0 passes it) reaches the parsedPage < 1 check and is rejected with this 400 error.","triggerScenarios":"GET agent requests with ?page=0. This is the only digit string that passes /^\\d+$/ but fails the range check for pages.","commonSituations":"0-indexed pagination logic being sent directly to a 1-indexed API; loop initializers starting at i=0 for page params; clients computing page = offset / limit where offset is 0.","solutions":["Use ?page=1 for the first page (pages are 1-indexed)","Convert 0-indexed page variables: page = zeroIndex + 1","Clamp client-side: Math.max(1, page)","Omit the page parameter entirely to default to page 1"],"exampleFix":"// before\nconst url = `/requests?page=${pageIndex}` // pageIndex = 0\n// after\nconst url = `/requests?page=${pageIndex + 1}`","handlingStrategy":"validation","validationCode":"function normalizePage(page) {\n  const n = Number.parseInt(String(page), 10)\n  return Number.isNaN(n) || n < 1 ? 1 : n\n}\nnormalizePage(searchParams.get(\"page\"))","typeGuard":"function isPageNumber(v) {\n  return typeof v === \"number\" && Number.isInteger(v) && v >= 1\n}","tryCatchPattern":"try {\n  return await fetchAgentRequests(agentId, { page })\n} catch (err) {\n  if (err.status === 400 && err.message === \"Page query must be greater than 0\") {\n    return fetchAgentRequests(agentId, { page: 1 })\n  }\n  throw err\n}","preventionTips":["Remember pages are 1-indexed; map 0-indexed counters with +1","Guard division-based page math (offset/limit) so it never yields 0 sent as page","Start pagination loops at page 1","Clamp with Math.max(1, page) before sending"],"tags":["validation","http-400","pagination","off-by-one"],"backgroundTag":"invalid-query-parameter","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}