Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Fix: updated critical path errors within studio (#40216)

Ali Waseem4d62c6d509c4
diff --git a/apps/studio/components/interfaces/SignIn/ResetPasswordForm.tsx b/apps/studio/components/interfaces/SignIn/ResetPasswordForm.tsx
index 48e513fe0e8..2d2955982c7 100644
--- a/apps/studio/components/interfaces/SignIn/ResetPasswordForm.tsx
+++ b/apps/studio/components/interfaces/SignIn/ResetPasswordForm.tsx
@@ -1,5 +1,4 @@
import { zodResolver } from '@hookform/resolvers/zod'
-import * as Sentry from '@sentry/nextjs'
import { Eye, EyeOff } from 'lucide-react'
import { useRouter } from 'next/router'
import { useState } from 'react'
@@ -7,6 +6,7 @@ import { useForm } from 'react-hook-form'
import { toast } from 'sonner'
import { z } from 'zod'
+import { captureCriticalError } from 'lib/error-reporting'
import { auth, getReturnToPath } from 'lib/gotrue'
import {
Button,
@@ -20,11 +20,6 @@ import {
import PasswordConditionsHelper from './PasswordConditionsHelper'
-const WHITELIST_ERRORS = [
- 'New password should be different from the old password',
- 'Password is known to be weak and easy to guess, please choose a different one',
-]
-
// Convert the existing yup passwordSchema to Zod
const passwordSchema = z.object({
password: z
@@ -70,9 +65,7 @@ const ResetPasswordForm = () => {
await router.push(getReturnToPath('/organizations'))
} else {
toast.error(`Failed to save password: ${error.message}`, { id: toastId })
- if (!WHITELIST_ERRORS.some((e) => error.message.includes(e))) {
- Sentry.captureMessage('[CRITICAL] Failed to reset password: ' + error.message)
- }
+ captureCriticalError(error, 'reset password')
}
}
diff --git a/apps/studio/components/interfaces/SignIn/SignInForm.tsx b/apps/studio/components/interfaces/SignIn/SignInForm.tsx
index 80ebf5f4923..e753bd35403 100644
--- a/apps/studio/components/interfaces/SignIn/SignInForm.tsx
+++ b/apps/studio/components/interfaces/SignIn/SignInForm.tsx
@@ -1,6 +1,5 @@
import HCaptcha from '@hcaptcha/react-hcaptcha'
import { zodResolver } from '@hookform/resolvers/zod'
-import * as Sentry from '@sentry/nextjs'
import type { AuthError } from '@supabase/supabase-js'
import { useQueryClient } from '@tanstack/react-query'
import Link from 'next/link'
@@ -14,6 +13,7 @@ import { useAddLoginEvent } from 'data/misc/audit-login-mutation'
import { getMfaAuthenticatorAssuranceLevel } from 'data/profile/mfa-authenticator-assurance-level-query'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { useLastSignIn } from 'hooks/misc/useLastSignIn'
+import { captureCriticalError } from 'lib/error-reporting'
import { auth, buildPathWithParams, getReturnToPath } from 'lib/gotrue'
import { Button, Form_Shadcn_, FormControl_Shadcn_, FormField_Shadcn_, Input_Shadcn_ } from 'ui'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
@@ -101,7 +101,7 @@ export const SignInForm = () => {
router.push(redirectPath)
} catch (error: any) {
toast.error(`Failed to sign in: ${(error as AuthError).message}`, { id: toastId })
- Sentry.captureMessage('[CRITICAL] Failed to sign in via EP: ' + error.message)
+ captureCriticalError(error, 'sign in via EP')
}
} else {
setCaptchaToken(null)
diff --git a/apps/studio/components/interfaces/SignIn/SignInSSOForm.tsx b/apps/studio/components/interfaces/SignIn/SignInSSOForm.tsx
index e0138863317..854fcae40f5 100644
--- a/apps/studio/components/interfaces/SignIn/SignInSSOForm.tsx
+++ b/apps/studio/components/interfaces/SignIn/SignInSSOForm.tsx
@@ -1,6 +1,5 @@
import HCaptcha from '@hcaptcha/react-hcaptcha'
import { zodResolver } from '@hookform/resolvers/zod'
-import * as Sentry from '@sentry/nextjs'
import { useQueryClient } from '@tanstack/react-query'
import { useRef, useState } from 'react'
import { type SubmitHandler, useForm } from 'react-hook-form'
@@ -9,12 +8,11 @@ import z from 'zod'
import { useLastSignIn } from 'hooks/misc/useLastSignIn'
import { BASE_PATH } from 'lib/constants'
+import { captureCriticalError } from 'lib/error-reporting'
import { auth, buildPathWithParams } from 'lib/gotrue'
import { Button, Form_Shadcn_, FormControl_Shadcn_, FormField_Shadcn_, Input_Shadcn_ } from 'ui'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
-const WHITELIST_ERRORS = ['No SSO provider assigned for this domain']
-
const schema = z.object({
email: z.string().min(1, 'Email is required').email('Must be a valid email'),
})
@@ -69,10 +67,7 @@ export const SignInSSOForm = () => {
setCaptchaToken(null)
captchaRef.current?.resetCaptcha()
toast.error(`Failed to sign in: ${error.message}`, { id: toastId })
-
- if (!WHITELIST_ERRORS.includes(error.message)) {
- Sentry.captureMessage('[CRITICAL] Failed to sign in via SSO: ' + error.message)
- }
+ captureCriticalError(error, 'sign in via SSO')
}
}
diff --git a/apps/studio/components/interfaces/SignIn/SignInWithCustom.tsx b/apps/studio/components/interfaces/SignIn/SignInWithCustom.tsx
index 03730971fce..f5959dd23ce 100644
--- a/apps/studio/components/interfaces/SignIn/SignInWithCustom.tsx
+++ b/apps/studio/components/interfaces/SignIn/SignInWithCustom.tsx
@@ -1,8 +1,8 @@
-import * as Sentry from '@sentry/nextjs'
import { useState } from 'react'
import { toast } from 'sonner'
import { BASE_PATH } from 'lib/constants'
+import { captureCriticalError } from 'lib/error-reporting'
import { auth, buildPathWithParams } from 'lib/gotrue'
import { Button } from 'ui'
@@ -35,7 +35,7 @@ export const SignInWithCustom = ({ providerName }: SignInWithCustomProps) => {
if (error) throw error
} catch (error: any) {
toast.error(`Failed to sign in via ${providerName}: ${error.message}`)
- Sentry.captureMessage('[CRITICAL] Failed to sign in via GH: ' + error.message)
+ captureCriticalError(error, `sign in via ${providerName}`)
setLoading(false)
}
}
diff --git a/apps/studio/components/interfaces/SignIn/SignInWithGitHub.tsx b/apps/studio/components/interfaces/SignIn/SignInWithGitHub.tsx
index 715b945721a..3431b56c89e 100644
--- a/apps/studio/components/interfaces/SignIn/SignInWithGitHub.tsx
+++ b/apps/studio/components/interfaces/SignIn/SignInWithGitHub.tsx
@@ -1,4 +1,3 @@
-import * as Sentry from '@sentry/nextjs'
import { Github } from 'lucide-react'
import { useState } from 'react'
import { toast } from 'sonner'
@@ -6,6 +5,7 @@ import { toast } from 'sonner'
import { BASE_PATH } from 'lib/constants'
import { useLastSignIn } from 'hooks/misc/useLastSignIn'
+import { captureCriticalError } from 'lib/error-reporting'
import { auth, buildPathWithParams } from 'lib/gotrue'
import { Button } from 'ui'
import { LastSignInWrapper } from './LastSignInWrapper'
@@ -36,7 +36,7 @@ export const SignInWithGitHub = () => {
else setLastSignInUsed('github')
} catch (error: any) {
toast.error(`Failed to sign in via GitHub: ${error.message}`)
- Sentry.captureMessage('[CRITICAL] Failed to sign in via GH: ' + error.message)
+ captureCriticalError(error, 'sign in via GitHub')
setLoading(false)
}
}
diff --git a/apps/studio/data/misc/reset-password-mutation.ts b/apps/studio/data/misc/reset-password-mutation.ts
index 1b302852661..3fc03ce8fef 100644
--- a/apps/studio/data/misc/reset-password-mutation.ts
+++ b/apps/studio/data/misc/reset-password-mutation.ts
@@ -1,12 +1,10 @@
-import * as Sentry from '@sentry/nextjs'
import { useMutation } from '@tanstack/react-query'
import { toast } from 'sonner'
import { handleError, post } from 'data/fetchers'
+import { captureCriticalError } from 'lib/error-reporting'
import type { ResponseError, UseCustomMutationOptions } from 'types'
-const WHITELIST_ERRORS = ['email must be an email']
-
export type ResetPasswordVariables = {
email: string
hcaptchaToken: string | null
@@ -44,9 +42,7 @@ export const useResetPasswordMutation = ({
} else {
onError(data, variables, context)
}
- if (!WHITELIST_ERRORS.some((error) => data.message.includes(error))) {
- Sentry.captureMessage('[CRITICAL] Failed to send reset password email: ' + data.message)
- }
+ captureCriticalError(data, 'send reset password email')
},
...options,
})
diff --git a/apps/studio/data/misc/signup-mutation.ts b/apps/studio/data/misc/signup-mutation.ts
index 73530e341fa..bb06a6a82d7 100644
--- a/apps/studio/data/misc/signup-mutation.ts
+++ b/apps/studio/data/misc/signup-mutation.ts
@@ -1,18 +1,10 @@
-import * as Sentry from '@sentry/nextjs'
import { useMutation } from '@tanstack/react-query'
import { toast } from 'sonner'
import { handleError, post } from 'data/fetchers'
+import { captureCriticalError } from 'lib/error-reporting'
import type { ResponseError, UseCustomMutationOptions } from 'types'
-const WHITELIST_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',
- 'email must be an email',
- 'Password is known to be weak and easy to guess, please choose a different one',
-]
-
export type SignUpVariables = {
email: string
password: string
@@ -51,9 +43,7 @@ export const useSignUpMutation = ({
} else {
onError(data, variables, context)
}
- if (!WHITELIST_ERRORS.some((error) => data.message.includes(error))) {
- Sentry.captureMessage('[CRITICAL] Failed to sign up: ' + data.message)
- }
+ captureCriticalError(data, 'sign up')
},
...options,
})
diff --git a/apps/studio/data/profile/mfa-challenge-and-verify-mutation.ts b/apps/studio/data/profile/mfa-challenge-and-verify-mutation.ts
index 6cb56b6a441..ad89d2332e9 100644
--- a/apps/studio/data/profile/mfa-challenge-and-verify-mutation.ts
+++ b/apps/studio/data/profile/mfa-challenge-and-verify-mutation.ts
@@ -1,14 +1,12 @@
-import * as Sentry from '@sentry/nextjs'
import type { AuthMFAVerifyResponse, MFAChallengeAndVerifyParams } from '@supabase/supabase-js'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
+import { captureCriticalError } from 'lib/error-reporting'
import { auth } from 'lib/gotrue'
import { profileKeys } from './keys'
import { UseCustomMutationOptions } from 'types'
-const WHITELIST_ERRORS = ['Invalid TOTP code entered']
-
interface MFAChallengeAndVerifyVariables extends MFAChallengeAndVerifyParams {
refreshFactors?: boolean
}
@@ -60,9 +58,7 @@ export const useMfaChallengeAndVerifyMutation = ({
} else {
onError(data, variables, context)
}
- if (!WHITELIST_ERRORS.some((error) => data.message.includes(error))) {
- Sentry.captureMessage('[CRITICAL] Failed to sign in via MFA: ' + data.message)
- }
+ captureCriticalError(data, 'sign in via MFA')
},
...options,
})
diff --git a/apps/studio/data/projects/project-create-mutation.ts b/apps/studio/data/projects/project-create-mutation.ts
index 77fa75b68f0..aedbed01525 100644
--- a/apps/studio/data/projects/project-create-mutation.ts
+++ b/apps/studio/data/projects/project-create-mutation.ts
@@ -1,24 +1,14 @@
-import * as Sentry from '@sentry/nextjs'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
import type { components } from 'data/api'
import { handleError, post } from 'data/fetchers'
+import { captureCriticalError } from 'lib/error-reporting'
import { PROVIDERS } from 'lib/constants'
import type { ResponseError, UseCustomMutationOptions } from 'types'
import { projectKeys } from './keys'
import { DesiredInstanceSize, PostgresEngine, ReleaseChannel } from './new-project.constants'
-const WHITELIST_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.',
-]
-
type CreateProjectBody = components['schemas']['CreateProjectBody']
type CloudProvider = CreateProjectBody['cloud_provider']
@@ -112,9 +102,7 @@ export const useProjectCreateMutation = ({
} else {
onError(data, variables, context)
}
- if (!WHITELIST_ERRORS.some((error) => data.message.includes(error))) {
- Sentry.captureMessage('[CRITICAL] Failed to create project: ' + data.message)
- }
+ captureCriticalError(data, 'create project')
},
...options,
})
diff --git a/apps/studio/lib/error-reporting.ts b/apps/studio/lib/error-reporting.ts
new file mode 100644
index 00000000000..d4b719d4540
--- /dev/null
+++ b/apps/studio/lib/error-reporting.ts
@@ -0,0 +1,115 @@
+import * as Sentry from '@sentry/nextjs'
+
+import { ResponseError } from 'types'
+
+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 message to Sentry, filtering out whitelisted errors.
+ *
+ * @param error - The error object (ResponseError, Error, or any object with a message property)
+ * @param context - The context/action that failed (e.g., 'reset password', 'sign up', 'create project')
+ *
+ * @example
+ * captureCriticalError(error, 'reset password')
+ * // Captures: '[CRITICAL][reset password] Failed: <error.message>'
+ *
+ * @example
+ * captureCriticalError(error, 'sign up')
+ * // Captures: '[CRITICAL][sign up] Failed: <error.message>'
+ */
+export function captureCriticalError(
+ error: ResponseError | Error | { message: string },
+ context: string
+): void {
+ const errorMessage = error instanceof Error ? error.message : error.message
+ if (!errorMessage) {
+ return
+ }
+
+ if (error instanceof ResponseError) {
+ handleResponseError(error, context)
+ return
+ }
+ if (error instanceof Error) {
+ handleError(error, context)
+ return
+ }
+
+ handleUnknownError(error, context)
+}
+
+function handleResponseError(error: ResponseError, context: string) {
+ const { code, message, requestPathname } = error
+ if (!requestPathname || !code) {
+ captureMessage({
+ message: `[CRITICAL][${context}] Failed w/ Response Error (no code or requestPathname): ${error.message}`,
+ context,
+ })
+ return
+ }
+
+ if (code >= 500) {
+ // Only capture 5XX errors as critical errors
+ captureMessage({
+ context,
+ message: `[CRITICAL][${context}] Failed requestPathname: ${requestPathname}: ${message}`,
+ })
+ return
+ }
+}
+
+function handleError(error: Error, context: string) {
+ const errorMessage = error.message
+ if (!errorMessage) {
+ return
+ }
+
+ captureMessage({
+ message: `[CRITICAL][${context}] Failed: ${errorMessage}`,
+ context,
+ })
+}
+
+function handleUnknownError(error: unknown, context: string) {
+ const hasMessage =
+ error && typeof error === 'object' && 'message' in error && typeof error.message === 'string'
+
+ if (hasMessage) {
+ captureMessage({
+ message: `[CRITICAL][${context}] Failed: ${error.message}`,
+ context,
+ })
+ }
+}
+
+function captureMessage({ message, context }: CaptureMessageOptions) {
+ if (WHITELIST_ERRORS.some((whitelisted) => message.includes(whitelisted))) {
+ return
+ }
+ Sentry.captureMessage(`[CRITICAL][${context}] ${message}`)
+}