Budibase/budibase · warning · HTTPError

Invalid ${queryName} query

Error message

Invalid ${queryName} query

What it means

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").

Source

Thrown at packages/server/src/api/controllers/ai/agentLogs.ts:74

  return parsedLimit
}

function sanitizeDateQuery(
  value: string | undefined,
  queryName: "startDate" | "endDate"
): string | undefined {
  const normalizedValue = value?.trim()
  if (!normalizedValue) {
    return undefined
  }

  if (DATE_ONLY_REGEX.test(normalizedValue)) {
    return normalizedValue
  }

  const parsedDate = new Date(normalizedValue)
  if (!Number.isFinite(parsedDate.getTime())) {
    throw new HTTPError(`Invalid ${queryName} query`, 400)
  }

  return parsedDate.toISOString()
}

function sanitizeEnvironmentQuery(environment?: string): AgentLogEnvironment {
  const normalizedEnvironment = environment?.trim()
  if (
    normalizedEnvironment === "development" ||
    normalizedEnvironment === "production"
  ) {
    return normalizedEnvironment
  }

  throw new HTTPError("Invalid environment query", 400)
}

function getComparableDate(value: string, mode: "start" | "end"): number {

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Send ISO 8601 strings (e.g. 2026-08-28 or 2026-08-28T00:00:00Z)
  2. Format dates with toISOString() on the client before sending
  3. Validate dates client-side before constructing the request

Example fix

// before
fetch(`/api/ai/agent/logs?startDate=28/08/2026`)
// after
fetch(`/api/ai/agent/logs?startDate=${new Date("2026-08-28").toISOString()}`)
Defensive patterns

Strategy: validation

Validate before calling

const d = new Date(value); if (isNaN(d.getTime())) throw new Error(`${name} must be a valid ISO date`)

Type guard

const isParseableDate = (v: unknown): v is string => typeof v === "string" && !Number.isNaN(new Date(v).getTime())

Try / catch

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 }

Prevention

When it happens

Trigger: GET agent logs with ?startDate=not-a-date, ?endDate=31/02/2026 (invalid calendar date), or locale-formatted strings Date.parse cannot interpret.

Common situations: Client sending localized date formats (dd/mm/yyyy); sending datetime strings with timezone quirks the JS parser rejects; UI sending placeholder text.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/1d2555d052df0b5a. Report an issue: GitHub.