mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
Drops the remaining Next-era shims and aliases that only existed for the dual runtime (FE-3106). Part 14 of the stack. **Depends on:** #53222 **Changed:** - ~45 files – import Sentry from `@sentry/react` directly instead of the aliased `@sentry/nextjs` - `hooks/ui/usePreventNavigationOnUnsavedChanges.ts` – is now the TanStack `useBlocker` implementation (previously swapped in by a Vite alias) - `components/interfaces/App/RouteValidationWrapper.tsx` – `next/router` → `useNavigate` + the leaf route's `fullPath` (`/project/$ref/sql/$id`) for the exempt-route and last-visited checks - `hooks/misc/withAuth.tsx` – no `getLayout` forwarding - `TemplateEditor.test.tsx` – renders inside a router for the unsaved-changes blocker **Removed:** - `compat/sentry-nextjs.ts` and its Vite alias, the `usePreventNavigationOnUnsavedChanges` alias and Next hook, `types/next.ts` (`NextPageWithLayout`), the `@sentry/nextjs` dependency The `compat/next/*` shims for `link`, `router`, `head`, `image`, `navigation`, `dynamic` and `script` stay: about 300 components outside `routes/**` still import them. Addresses [FE-3106](https://linear.app/supabase/issue/FE-3106/move-page-bodies-into-route-files-and-delete-pages). ## To test - Trigger an error (e.g. a failing query) – it reaches Sentry as before - Edit an email template or edge function and navigate away – the unsaved-changes prompt appears - Open an org you don't belong to – toast and redirect home; open a SQL snippet, leave and come back – last snippet is restored --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
119 lines
3.4 KiB
TypeScript
119 lines
3.4 KiB
TypeScript
import * as Sentry from '@sentry/react'
|
|
|
|
import type { StudioError } from '@/lib/errors/studio-errors'
|
|
import { isStudioError } from '@/lib/errors/studio-errors'
|
|
|
|
type CaptureMessageOptions = {
|
|
context: string
|
|
message: string
|
|
}
|
|
|
|
const WHITELIST_ERRORS = [
|
|
// Common validation errors
|
|
'email must be an email',
|
|
'Password is known to be weak and easy to guess, please choose a different one',
|
|
// Authentication errors
|
|
'A user with this email already exists',
|
|
'Password should contain at least one character of each',
|
|
'You attempted to send email to an inactive recipient',
|
|
'New password should be different from the old password',
|
|
'Invalid TOTP code entered',
|
|
'No SSO provider assigned for this domain',
|
|
// Project creation errors
|
|
'The following organization members have reached their maximum limits for the number of active free projects',
|
|
'db_pass must be longer than or equal to 4 characters',
|
|
'There are overdue invoices in the organization(s)',
|
|
'name should not contain a . string',
|
|
'Project creation in the Supabase dashboard is disabled for this Vercel-managed organization.',
|
|
'Your account, which is handled by the Fly Supabase extension, cannot access this endpoint.',
|
|
'already exists in your organization.',
|
|
]
|
|
|
|
/**
|
|
* Captures a critical error to Sentry, filtering out whitelisted errors.
|
|
*
|
|
* @param error - The error object (StudioError, Error, or any object with a message property)
|
|
* @param context - The context/action that failed (e.g., 'reset password', 'sign up', 'create project')
|
|
* Attached as the `context` tag on the Sentry event.
|
|
*/
|
|
export function captureCriticalError(
|
|
error: StudioError | Error | { message: string },
|
|
context: string
|
|
): void {
|
|
if (!error.message) {
|
|
return
|
|
}
|
|
|
|
if (isStudioError(error)) {
|
|
handleResponseError(error, context)
|
|
return
|
|
}
|
|
if (error instanceof Error) {
|
|
handleError(error, context)
|
|
return
|
|
}
|
|
|
|
handleUnknownAPIResponseError(error, context)
|
|
}
|
|
|
|
function handleResponseError(error: StudioError, context: string) {
|
|
const { code, message, endpoint } = error
|
|
if (!endpoint || !code) {
|
|
captureMessage({
|
|
message: `Response Error (no code or endpoint) w/ message: ${error.message}`,
|
|
context,
|
|
})
|
|
return
|
|
}
|
|
|
|
if (code >= 500) {
|
|
// Only capture 5XX errors as critical errors
|
|
captureMessage({
|
|
context,
|
|
message: `endpoint ${endpoint} w/ message: ${message}`,
|
|
})
|
|
return
|
|
}
|
|
}
|
|
|
|
function handleError(error: Error, context: string) {
|
|
if (!error.message) {
|
|
return
|
|
}
|
|
|
|
captureMessage({
|
|
message: error.message,
|
|
context,
|
|
})
|
|
}
|
|
|
|
function handleUnknownAPIResponseError(error: unknown, context: string) {
|
|
if (
|
|
error &&
|
|
typeof error === 'object' &&
|
|
'message' in error &&
|
|
typeof error.message === 'string'
|
|
) {
|
|
captureMessage({
|
|
message: error.message,
|
|
context,
|
|
})
|
|
}
|
|
}
|
|
|
|
function captureMessage({ message, context }: CaptureMessageOptions) {
|
|
if (WHITELIST_ERRORS.some((whitelisted) => message.includes(whitelisted))) {
|
|
return
|
|
}
|
|
// Use captureException (vs captureMessage) so these appear as exceptions in Sentry
|
|
// and can have dedicated alert rules. Grouping is still by message since all
|
|
// CriticalErrors share the same synthetic stack trace.
|
|
Sentry.withScope((scope) => {
|
|
scope.setTag('critical', 'true')
|
|
scope.setTag('context', context)
|
|
const error = new Error(message)
|
|
error.name = `CriticalError`
|
|
Sentry.captureException(error)
|
|
})
|
|
}
|