{"record":{"id":"abd4c21d0c1d7a92","repo":"Budibase/budibase","slug":"invalid-page-query","errorCode":null,"errorMessage":"Invalid page query","messagePattern":"Invalid page query","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/api/controllers/ai/agentRequests.ts","lineNumber":37,"sourceCode":"    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\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","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/ai/agentRequests.ts#L19-L55","documentation":"Thrown by sanitizePageQuery when the `page` query parameter is not a pure digit string. A missing or whitespace-only page falls back to 1; anything failing /^\\d+$/ (e.g. 'two', '1.0', '0x1', '-1') is rejected with this 400 error.","triggerScenarios":"GET agent requests with ?page=first, ?page=1.0, ?page=-1, or page values interpolated from non-numeric variables such as 'null' or 'undefined' strings.","commonSituations":"Pagination components passing the raw string from an input box; array-index-based page variables that are undefined on first render; URLs shared with hand-edited page params; confusion between 0-indexed and 1-indexed pages leading to '0' (which passes regex but fails the >0 check).","solutions":["Send a plain positive integer, e.g. ?page=2","Omit the page parameter to start at page 1","Validate/coerce the page value client-side before building the URL","Fix template code that stringifies undefined/null into the query"],"exampleFix":"// before\nconst url = `/requests?page=${currentPage}` // currentPage = undefined\n// after\nconst url = `/requests?page=${parseInt(currentPage, 10) || 1}`","handlingStrategy":"validation","validationCode":"function sanitizePage(page) {\n  if (page === undefined || page === null || String(page).trim() === \"\") return 1\n  const s = String(page).trim()\n  if (!/^\\d+$/.test(s)) throw new Error(\"page must be an integer\")\n  const n = parseInt(s, 10)\n  if (n < 1) throw new Error(\"page must be greater than 0\")\n  return n\n}\nsanitizePage(searchParams.get(\"page\"))","typeGuard":"function isPositiveIntegerString(v) {\n  return typeof v === \"string\" && /^\\d+$/.test(v) && parseInt(v, 10) >= 1\n}","tryCatchPattern":"try {\n  return await fetchAgentRequests(agentId, { page })\n} catch (err) {\n  if (err.status === 400 && err.message === \"Invalid page query\") {\n    return fetchAgentRequests(agentId, { page: 1 })\n  }\n  throw err\n}","preventionTips":["Default page to 1 whenever the value is missing or non-numeric","Use 1-indexed pagination consistently; convert from 0-indexed variables","Coerce with parseInt(..., 10) before interpolating into URLs","Hide/disable page inputs until a numeric page value exists"],"tags":["validation","http-400","pagination","query-params"],"backgroundTag":"invalid-query-parameter","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}