studio-error-handling
por supabase
Patrón de visualización de errores y solución de problemas para Supabase Studio. Úselo cuando
npx skills add https://github.com/supabase/supabase --skill studio-error-handlingStudio Error Handling Pattern
Full architecture, SQLSTATE predicates, and mapping walkthrough: apps/studio/components/interfaces/ErrorHandling/README.md
How it works
handleError() → throws tagged StudioError → React Query catches → ErrorMatcher / AlertError renders UI
- Tagged errors:
handleError(@/data/fetchers) throws EffectData.TaggedErrorinstances (_tag,fault: user | platform | third_party | studio,reason,classifiedBy: rule | default,retryable,service, plus legacymessage,code,requestId, …). Check withisStudioError(e)from@/lib/errors/studio-errors, neverinstanceof;StudioErroris a union type only. - API vs non-API classifiers (
data/error-classification.ts):classifyResponseError({ message, code })is for HTTP API responses only (ERROR_PATTERNSwin, else 5xxPlatformError, 4xxUnclassifiedApiError, no statusUnexpectedError— never pass a made-up status).classifyError(e)handles everything else (tagged passes through,AbortError→RequestAborted, browser fetch failure →NetworkUnreachable, elseUnexpectedError). Successful JSONGETs still empty after recovery reject from the fetch layer asMalformedResponseError(normalizeEmptyBodyResponse) without hittinghandleError(reportQueryErrorstill reports it). - SQL errors:
executeSqlruns pg-meta errors throughclassifySqlResponseError: user/AI SQL becomesUserSqlError(never sent to Sentry); Studio SQL becomesStudioSqlError(redacted message, staticqueryNamerequired; markedfault: 'user',reason: 'user_input'whenisUserFaultSqlStateaccepts the SQLSTATE via composableisUserFaultForValues(typed values: filters, row edits) orisUserFaultForSql(embedded SQL: policies, functions) indata/error-classification.ts). - Privacy & Sentry sampling: the class decides privacy (
UserSqlErrornever sent,StudioSqlErrorredacted), whileERROR_ROUTING(lib/errors/error-routing.ts) maps every tag + fault to{ sentrySampleRate }(SAMPLE_NEVER/SAMPLE_USER_FAULT/SAMPLE_OTHER/SAMPLE_OWNED/SAMPLE_ALWAYS, looked up viagetErrorRouting).reportStudioErrortagssample_rate(enforced inbeforeSend) and setserrorEventId. - Reporting timing:
QueryCache/MutationCacheonError(reportQueryError) reports once after the final retry usingsentryContextandalwaysCaptureremembered byhandleError. PassreportImmediately: truetohandleErroronly for callers outside React Query.
Key files
| File | Purpose |
|---|---|
apps/studio/data/error-patterns.ts | ERROR_PATTERN_MAP (Map<ErrorConstructor, RegExp>) — regex lives here, never in UI components |
apps/studio/lib/errors/studio-errors.ts | Tagged error classes, StudioError union type, isStudioError |
apps/studio/data/error-classification.ts | classifyResponseError, classifyError, classifySqlResponseError, predicates |
apps/studio/lib/errors/error-routing.ts | ERROR_ROUTING table per tag and fault, getErrorRouting |
apps/studio/components/interfaces/ErrorHandling/ErrorMatcher.tsx | Looks up error class in error-mappings.tsx and renders troubleshooting UI |
apps/studio/components/interfaces/ErrorHandling/error-mappings.tsx | Map<ErrorConstructor, ErrorMapping> ({ id, Troubleshooting }) |
apps/studio/components/interfaces/ErrorHandling/errorMappings/ConnectionTimeout.tsx | Reference troubleshooting component (including AI Assistant debug button wiring) |
apps/studio/components/interfaces/ErrorHandling/TroubleshootingSections.tsx | Reusable accordion section components |
apps/studio/components/interfaces/ErrorHandling/TroubleshootingAccordion.tsx | Accordion wrapper with telemetry |
Which component
| Situation | Use |
|---|---|
| Query failed and page/section cannot render its data (default across Studio) | AlertError from @/components/ui/AlertError |
| Error may be a classified class with troubleshooting steps (e.g. timeout) | ErrorMatcher from @/components/interfaces/ErrorHandling/ErrorMatcher — pass fallback for unclassified errors |
| Mutation failed | The mutation hook's default onError toast (toast.error from sonner) — don't render an alert (see studio-queries) |
AlertError (default)
if (isError) return <AlertError error={error} subject="Failed to retrieve invoices" />
- Phrase
subjectasFailed to <verb> <thing>and passprojectRefin project context to pre-fill the support link.503responses are reworded automatically. - For
StudioErrors,getErrorPresentation(AlertError.utils.ts) applies tag/fault defaults (caller props win): displaysrequestId,errorEventId("before sampling"), and Copy details (formatErrorDetailsstripsformattedError,metadata,cause, SQL, and SQL error messages).fault: 'user'hides support/IDs/copy; offlineNetworkUnreachableshows a dedicated offline message. - Use
additionalActionsfor retry/navigation; usehideContactSupportonly when support cannot help on a non-user fault. Prefer early return for primary data and inline{isError && <AlertError … />}for secondary panels. - System-fault assumption:
AlertError's default copy for plain or non-user-fault errors (including unclassified 4xxs) tells users to refresh/contact support — don't use it blindly for mutation or client-side user-input errors; use the mutation'sonErrortoast or actionable inline copy instead. - Never collapse errors into empty states: check
isErrorbefore rendering empty states, and distinguish unparseable/dropped records from genuinely empty responses. - Multi-query views: consolidate errors into a single
AlertErrorrather than sprawling multiple banners, and hide dependent sub-sections whose prerequisite query failed.
ErrorMatcher (classified errors)
Reach for ErrorMatcher when adding dedicated troubleshooting steps for a classified error class (not as a general replacement for AlertError). Pass the full error object from React Query, never error.message:
{
isError && (
<ErrorMatcher title="Failed to load tables" error={error} supportFormParams={{ projectRef }} />
)
}
What NOT to do
- Do not pass
error.messagetoErrorMatcher, put regex inerror-mappings.tsx, or useObject.assignto stamp_tag(add a tagged class + pattern indata/error-patterns.ts). - Do not pass a raw support URL (use
supportFormParams={{ projectRef }}), put page titles inside error mappings, or add callback props (onDebugWithAI,onRestartProject) to troubleshooting components (use hooks inside them). - Do not assume caught
unknownrejections areErrorinstances (external/WASM libraries can reject with non-Errors) — usegetErrorMessagefrom@/lib/get-error-message. - Handle an error's user-facing side effect (toast or inline alert) in a single layer — do not toast and also rethrow to a caller that surfaces errors (or leave an unhandled rejection).