supabase/supabase · error · Error

Start date is required

Error message

Start date is required

What it means

Third guard in getInfraMonitoringAttributes: throws 'Start date is required' when startDate is falsy. The endpoint needs a time window; without a lower bound the query is rejected client-side.

Source

Thrown at apps/studio/data/analytics/infra-monitoring-query.ts:66

  endDate?: string
  interval?: InfraMonitoringInterval
  databaseIdentifier?: string
}

export async function getInfraMonitoringAttributes(
  {
    projectRef,
    attributes,
    startDate,
    endDate,
    interval = '1h',
    databaseIdentifier,
  }: InfraMonitoringMultiVariables,
  signal?: AbortSignal
) {
  if (!projectRef) throw new Error('Project ref is required')
  if (!attributes?.length) throw new Error('At least one attribute is required')
  if (!startDate) throw new Error('Start date is required')
  if (!endDate) throw new Error('End date is required')

  // Backend doesn't support 2m granularity, so request 1m and aggregate in frontend
  const is2MinInterval = interval === '2m'
  const requestInterval: AnalyticsInterval = is2MinInterval ? '1m' : (interval as AnalyticsInterval)

  const { data, error } = await get('/platform/projects/{ref}/infra-monitoring', {
    params: {
      path: { ref: projectRef },
      // Attributes support is not yet reflected in the generated client types.
      query: {
        attributes,
        startDate,
        endDate,
        interval: requestInterval,
        databaseIdentifier,
      } as any,
    },

View on GitHub (pinned to beee91b9c2)

Solutions

  1. Compute a default startDate (e.g. now - 24h) synchronously at the call site, not in an effect.
  2. Gate with `enabled: !!startDate`.
  3. Validate startDate parses to a valid ISO string before submitting.

Example fix

// before
useInfraMonitoringQuery({ projectRef, attributes, startDate, endDate })

// after
const defaultStart = useMemo(() => dayjs().subtract(24, 'hour').toISOString(), [])
useInfraMonitoringQuery(
  { projectRef, attributes, startDate: startDate ?? defaultStart, endDate },
  { enabled: !!(projectRef && attributes?.length && endDate) }
)
Defensive patterns

Strategy: validation

Validate before calling

// Compute default window synchronously, not in an effect.
const startDate = useMemo(() => dayjs().subtract(24, 'hour').toISOString(), [])
const endDate = useMemo(() => dayjs().toISOString(), [])
useQuery({
  queryKey: ['infra-monitoring', projectRef, attributes, startDate, endDate],
  queryFn: ({ signal }) =>
    getInfraMonitoringAttributes({ projectRef, attributes, startDate, endDate }, signal),
  enabled: !!(projectRef && attributes?.length),
})

Type guard

function isIsoDate(v: unknown): v is string {
  return typeof v === 'string' && Number.isFinite(Date.parse(v))
}

Try / catch

try {
  const attrs = await getInfraMonitoringAttributes({ projectRef, attributes, startDate, endDate })
} catch (e) {
  if (e instanceof Error && e.message === 'Start date is required') return
  throw e
}

Prevention

When it happens

Trigger: Time-range picker not initialized; user cleared the start date; relative-range helper returned undefined for startDate; SSR before the default window is computed.

Common situations: Date picker defaults applied via useEffect after first render; deep-link without a start param; clock/timezone utils returning undefined for an edge-case input.

Related errors


AI-assisted analysis of supabase/supabase@beee91b9c2 (2026-08-12). Data as JSON: /api/errors/d2c2d552ea3ffb4d. Report an issue: GitHub.