Compare commits

...

1 Commits

Author SHA1 Message Date
seer-by-sentry[bot]
5eaaba47e6 fix(frontend): Prevent errors in Sentry LaunchDarkly flag handler from breaking the app 2025-10-20 21:18:34 +00:00
2 changed files with 26 additions and 2 deletions

View File

@@ -52,7 +52,7 @@
"@rjsf/core": "5.24.13",
"@rjsf/utils": "5.24.13",
"@rjsf/validator-ajv8": "5.24.13",
"@sentry/nextjs": "10.15.0",
"@sentry/nextjs": "10.20.0",
"@supabase/ssr": "0.6.1",
"@supabase/supabase-js": "2.55.0",
"@tanstack/react-query": "5.85.3",

View File

@@ -10,6 +10,30 @@ import * as Sentry from "@sentry/nextjs";
const clientId = process.env.NEXT_PUBLIC_LAUNCHDARKLY_CLIENT_ID;
const envEnabled = process.env.NEXT_PUBLIC_LAUNCHDARKLY_ENABLED === "true";
/**
* Creates a defensive wrapper around Sentry's LaunchDarkly flag handler
* to catch and prevent any errors from breaking the application.
*/
function createSafeLaunchDarklyFlagHandler() {
try {
const handler = Sentry.buildLaunchDarklyFlagUsedHandler();
// Wrap the handler to catch any runtime errors
return (flagKey: string, detail: any) => {
try {
handler(flagKey, detail);
} catch (error) {
// Log the error to console but don't let it bubble up
console.error("Error in Sentry LaunchDarkly flag handler:", error);
}
};
} catch (error) {
// If building the handler fails, return a no-op function
console.error("Failed to build Sentry LaunchDarkly flag handler:", error);
return () => {};
}
}
export function LaunchDarklyProvider({ children }: { children: ReactNode }) {
const { user, isUserLoading } = useSupabase();
const isCloud = getBehaveAs() === BehaveAs.CLOUD;
@@ -48,7 +72,7 @@ export function LaunchDarklyProvider({ children }: { children: ReactNode }) {
reactOptions={{ useCamelCaseFlagKeys: false }}
options={{
bootstrap: "localStorage",
inspectors: [Sentry.buildLaunchDarklyFlagUsedHandler()],
inspectors: [createSafeLaunchDarklyFlagHandler()],
}}
>
{children}