{"record":{"id":"1d2555d052df0b5a","repo":"Budibase/budibase","slug":"invalid-queryname-query","errorCode":null,"errorMessage":"Invalid ${queryName} query","messagePattern":"Invalid (.+?) query","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"warning","filePath":"packages/server/src/api/controllers/ai/agentLogs.ts","lineNumber":74,"sourceCode":"  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\n  const parsedDate = new Date(normalizedValue)\n  if (!Number.isFinite(parsedDate.getTime())) {\n    throw new HTTPError(`Invalid ${queryName} query`, 400)\n  }\n\n  return parsedDate.toISOString()\n}\n\nfunction sanitizeEnvironmentQuery(environment?: string): AgentLogEnvironment {\n  const normalizedEnvironment = environment?.trim()\n  if (\n    normalizedEnvironment === \"development\" ||\n    normalizedEnvironment === \"production\"\n  ) {\n    return normalizedEnvironment\n  }\n\n  throw new HTTPError(\"Invalid environment query\", 400)\n}\n\nfunction getComparableDate(value: string, mode: \"start\" | \"end\"): number {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/ai/agentLogs.ts#L56-L92","documentation":"sanitizeDateQuery validates a date query parameter (startDate/endDate) by attempting to parse it as a Date. If the value is neither a date-only string (DATE_ONLY_REGEX) nor parseable to a finite date, it throws HTTPError 400 naming the offending query (e.g. \"Invalid startDate query\").","triggerScenarios":"GET agent logs with ?startDate=not-a-date, ?endDate=31/02/2026 (invalid calendar date), or locale-formatted strings Date.parse cannot interpret.","commonSituations":"Client sending localized date formats (dd/mm/yyyy); sending datetime strings with timezone quirks the JS parser rejects; UI sending placeholder text.","solutions":["Send ISO 8601 strings (e.g. 2026-08-28 or 2026-08-28T00:00:00Z)","Format dates with toISOString() on the client before sending","Validate dates client-side before constructing the request"],"exampleFix":"// before\nfetch(`/api/ai/agent/logs?startDate=28/08/2026`)\n// after\nfetch(`/api/ai/agent/logs?startDate=${new Date(\"2026-08-28\").toISOString()}`)","handlingStrategy":"validation","validationCode":"const d = new Date(value); if (isNaN(d.getTime())) throw new Error(`${name} must be a valid ISO date`)","typeGuard":"const isParseableDate = (v: unknown): v is string => typeof v === \"string\" && !Number.isNaN(new Date(v).getTime())","tryCatchPattern":"try { await api.fetchAgentLogs({ startDate }) } catch (e) { if (e.status === 400 && e.message.startsWith(\"Invalid \") && e.message.includes(\"query\")) { /* correct the date format and retry */ } else throw e }","preventionTips":["Always send ISO 8601 dates (toISOString) in query params","Validate dates in the UI before submitting","Avoid locale-specific formats like dd/mm/yyyy"],"tags":["validation","dates","http-400"],"backgroundTag":"invalid-query-parameter","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}