From 58cb06acaeb40ee29e06ea2b347b673ad28a9f4b Mon Sep 17 00:00:00 2001 From: Evan Anderson Date: Tue, 5 Nov 2024 10:30:24 -0800 Subject: [PATCH] Fix nil flag client, and warn about use in future --- internal/flags/flags.go | 4 ++++ internal/service/service.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/flags/flags.go b/internal/flags/flags.go index 3a3215ee9c..0bfcfee2e0 100644 --- a/internal/flags/flags.go +++ b/internal/flags/flags.go @@ -39,6 +39,10 @@ func fromContext(ctx context.Context) openfeature.EvaluationContext { // Bool provides a simple wrapper around client.Boolean to normalize usage for Minder. func Bool(ctx context.Context, client openfeature.IClient, feature Experiment) bool { + if client == nil { + zerolog.Ctx(ctx).Debug().Str("flag", string(feature)).Msg("Bool called with client, returning false") + return false + } ret := client.Boolean(ctx, string(feature), false, fromContext(ctx)) // TODO: capture in telemetry records return ret diff --git a/internal/service/service.go b/internal/service/service.go index ff7a63e24a..72071aa910 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -76,7 +76,7 @@ func AllInOneServerService( flags.OpenFeatureProviderFromFlags(ctx, cfg.Flags) featureFlagClient := openfeature.NewClient(cfg.Flags.AppName) - evt, err := eventer.New(ctx, nil, &cfg.Events) + evt, err := eventer.New(ctx, featureFlagClient, &cfg.Events) if err != nil { return fmt.Errorf("unable to setup eventer: %w", err) }