Budibase/budibase · error · HTTPError
Invalid environment query
Error message
Invalid environment query
What it means
This error is thrown by the agent logs controller when the `environment` query parameter supplied to the agent log session endpoints is not one of the accepted values. The sanitizeEnvironmentQuery helper normalizes the input and only accepts 'development' or 'production'; anything else is rejected with a 400 HTTP error.
Source
Thrown at packages/server/src/api/controllers/ai/agentLogs.ts:89
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 {
const comparableValue = DATE_ONLY_REGEX.test(value)
? `${value}T${mode === "start" ? "00:00:00.000" : "23:59:59.999"}Z`
: value
return new Date(comparableValue).getTime()
}
export async function fetchAgentLogs(
ctx: UserCtx<void, FetchAgentLogsResponse>
) {
const { agentId } = ctx.params
const { startDate, endDate, bookmark, limit, statusFilter, triggerFilter } =
ctx.query as Record<string, string>
const defaults = getDefaultLogRange()
const sanitizedStartDate =View on GitHub (pinned to a81a902e9a)
Solutions
- Change the query to use exactly 'development' or 'production'
- Remove the environment query parameter entirely if the endpoint allows a default
- Check for typos and trim whitespace in the caller
- Update calling code that passes environment names from a broader enum (e.g. staging) to map them onto the two supported values
Example fix
// before GET /api/ai/agents/123/logs?environment=staging // after GET /api/ai/agents/123/logs?environment=development
Defensive patterns
Strategy: validation
Validate before calling
const ENVIRONMENTS = ["development", "production"]
function validateEnvironment(env) {
if (env !== undefined && !ENVIRONMENTS.includes(env)) {
throw new Error(`environment must be one of ${ENVIRONMENTS.join(" or ")}`)
}
return env
}
validateEnvironment(searchParams.get("environment")) Type guard
function isEnvironment(v) {
return v === "development" || v === "production"
} Try / catch
try {
const logs = await fetchAgentLogSession(agentId, session, { environment: env })
} catch (err) {
if (err.status === 400 && err.message === "Invalid environment query") {
throw new Error(`"${env}" is not supported; use "development" or "production"`)
}
throw err
} Prevention
- Constrain UI environment selectors to exactly development/production
- Trim and lowercase user input before sending
- Omit the environment param when you do not need to filter
- Share a single constants module for allowed environments between client and server
When it happens
Trigger: Calling GET on the agent logs endpoints (via fetchAgentLogSession) with ?environment=staging, ?environment=dev, ?environment=Production (uppercase is rejected if normalization does not lowercase first) or any other string not exactly matching 'development' or 'production' after normalization.
Common situations: CI scripts passing a branch or stage name (e.g. 'staging') as environment; frontend code mapping an app environment selector that includes more values than the API supports; typos like 'prod' or 'production ' with trailing whitespace that survives normalization.
Related errors
- startDate query must be before endDate query
- Invalid limit query
- Limit query must be between 1 and 100
- Invalid page query
- Invalid status query
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/dd127ffb058b6fea.
Report an issue: GitHub.