From 5811262cf20257104f69d3afb503553c32122da7 Mon Sep 17 00:00:00 2001 From: Cody Leff Date: Thu, 25 Aug 2022 15:53:18 -0700 Subject: [PATCH] Add warnings if feature flags are read before initialization. (#21201) --- .../superset-ui-core/src/utils/featureFlags.ts | 10 +++++++++- superset-frontend/src/featureFlags.ts | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts b/superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts index 93678d8d95..a2cb7c8368 100644 --- a/superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts +++ b/superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts @@ -84,5 +84,13 @@ declare global { } export function isFeatureEnabled(feature: FeatureFlag) { - return window && window.featureFlags && !!window.featureFlags[feature]; + try { + return !!window.featureFlags[feature]; + } catch (error) { + // eslint-disable-next-line no-console + console.error(`Failed to query feature flag ${feature} (see error below)`); + // eslint-disable-next-line no-console + console.error(error); + return false; + } } diff --git a/superset-frontend/src/featureFlags.ts b/superset-frontend/src/featureFlags.ts index 4d457fd527..ba902f07df 100644 --- a/superset-frontend/src/featureFlags.ts +++ b/superset-frontend/src/featureFlags.ts @@ -28,5 +28,13 @@ export function initFeatureFlags(featureFlags: FeatureFlagMap) { } export function isFeatureEnabled(feature: FeatureFlag) { - return window && window.featureFlags && !!window.featureFlags[feature]; + try { + return !!window.featureFlags[feature]; + } catch (error) { + // eslint-disable-next-line no-console + console.error(`Failed to query feature flag ${feature} (see error below)`); + // eslint-disable-next-line no-console + console.error(error); + return false; + } }