mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix(frontend): Prevent errors in Sentry LaunchDarkly flag handler from breaking the app
This commit is contained in:
committed by
GitHub
parent
47bb89caeb
commit
5eaaba47e6
@@ -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",
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user