mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem When Supavisor rejects a session because its connection pool is full, Studio shows the error without explaining how to recover. ## Fix Show a troubleshooting step for the session-mode limit that explains how pool size limits concurrent clients and links to the configuration guide. ## Screenshot The Table Editor’s troubleshooting step, rendered locally with a sample session-pool error. <img width="660" alt="Expanded Supavisor session pool limit guidance in the Table Editor" src="https://github.com/user-attachments/assets/6072eec4-e243-4d53-a40f-30fb14d21d05" /> ## How to test - Display a classified MaxClientsInSessionMode error in Studio and expand its troubleshooting step. The link should open the pool size section of the database connection management guide. - Display a generic transaction-mode connection limit error. It should keep its usual fallback. - The pattern, classification and ErrorMatcher suites exercise these paths (144 tests passed locally). Fixes [DEBUG-43](https://linear.app/supabase/issue/DEBUG-43).
76 lines
3.3 KiB
TypeScript
76 lines
3.3 KiB
TypeScript
import type { Fault, StudioError, StudioErrorTag } from '@/lib/errors/studio-errors'
|
|
|
|
/** Never send to Sentry. */
|
|
export const SAMPLE_NEVER = 0
|
|
/** Reads a 0-1 rate from an env var, falling back when it is unset or out of range. */
|
|
export function sampleRateFromEnv(value: string | undefined, fallback: number) {
|
|
if (value === undefined || value.trim() === '') return fallback
|
|
const rate = Number(value)
|
|
return Number.isFinite(rate) && rate >= 0 && rate <= 1 ? rate : fallback
|
|
}
|
|
|
|
// Env vars are read with literal `process.env.NEXT_PUBLIC_*` access so the Next and Vite builds can
|
|
// inline them.
|
|
|
|
/** Faults owned by other teams or services: keep a small sample for visibility. */
|
|
export const SAMPLE_OTHER = sampleRateFromEnv(process.env.NEXT_PUBLIC_SENTRY_SAMPLE_RATE_OTHER, 0.1)
|
|
/** Faults Studio owns and fixes. */
|
|
export const SAMPLE_OWNED = sampleRateFromEnv(
|
|
process.env.NEXT_PUBLIC_SENTRY_SAMPLE_RATE_OWNED,
|
|
0.25
|
|
)
|
|
/**
|
|
* Cap for errors whose fault is the user's. A trickle to catch misclassification and Studio bugs
|
|
* hiding in user faults.
|
|
*/
|
|
export const SAMPLE_USER_FAULT = sampleRateFromEnv(
|
|
process.env.NEXT_PUBLIC_SENTRY_SAMPLE_RATE_USER_FAULT,
|
|
0.01
|
|
)
|
|
/** Always send (also used when a caller forces capture). */
|
|
export const SAMPLE_ALWAYS = 1
|
|
|
|
export type Routing = {
|
|
sentrySampleRate: number
|
|
// TODO: add PostHog routing when errors are sent to PostHog
|
|
}
|
|
|
|
// For every tag, requires exactly the faults that class can have, so a new tag or a new possible
|
|
// fault fails typecheck until it is routed.
|
|
type ErrorRoutingTable = {
|
|
[Tag in StudioErrorTag]: Record<Extract<StudioError, { _tag: Tag }>['fault'], Routing>
|
|
}
|
|
|
|
// The class decides privacy (`isNeverReportedError`); this table gives the rate for each tag and
|
|
// fault. A user fault is rarely ours to fix, so it only gets a trickle (`SAMPLE_USER_FAULT`) to catch
|
|
// misclassification and Studio bugs hiding in it.
|
|
export const ERROR_ROUTING = {
|
|
RequestAborted: { user: { sentrySampleRate: SAMPLE_NEVER } },
|
|
NetworkUnreachable: {
|
|
user: { sentrySampleRate: SAMPLE_USER_FAULT }, // reason `offline`
|
|
platform: { sentrySampleRate: SAMPLE_OTHER },
|
|
},
|
|
MalformedResponse: { platform: { sentrySampleRate: SAMPLE_ALWAYS } },
|
|
PlatformError: { platform: { sentrySampleRate: SAMPLE_OTHER } },
|
|
UnclassifiedApiError: {
|
|
user: { sentrySampleRate: SAMPLE_USER_FAULT }, // 401, no valid session
|
|
studio: { sentrySampleRate: SAMPLE_OWNED },
|
|
},
|
|
DbConnectionTimeout: { platform: { sentrySampleRate: SAMPLE_OTHER } },
|
|
SupavisorSessionPool: { user: { sentrySampleRate: SAMPLE_USER_FAULT } },
|
|
UserSqlError: { user: { sentrySampleRate: SAMPLE_NEVER } },
|
|
StudioSqlError: {
|
|
user: { sentrySampleRate: SAMPLE_USER_FAULT }, // reason `user_input`
|
|
studio: { sentrySampleRate: SAMPLE_OWNED },
|
|
},
|
|
UnexpectedError: { studio: { sentrySampleRate: SAMPLE_OWNED } },
|
|
} as const satisfies ErrorRoutingTable
|
|
|
|
/** The routing for one error, by its tag and fault. */
|
|
export function getErrorRouting(error: StudioError): Routing {
|
|
// TypeScript can't correlate `_tag` with `fault` across the union, so view the table by plain
|
|
// keys. `ErrorRoutingTable` guarantees every real tag and fault pair is present.
|
|
const byFault: Partial<Record<Fault, Routing>> = ERROR_ROUTING[error._tag]
|
|
return byFault[error.fault] ?? { sentrySampleRate: SAMPLE_NEVER }
|
|
}
|