From e01a9cd9965142d5a4d4dd328168f1444cb0a5df Mon Sep 17 00:00:00 2001 From: Fredrik Oseberg Date: Wed, 27 Sep 2023 10:41:59 +0200 Subject: [PATCH] fix: add warning --- client.go | 3 +++ utils.go | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/client.go b/client.go index d4d1a71..0b929d0 100644 --- a/client.go +++ b/client.go @@ -340,10 +340,13 @@ func (uc *Client) isEnabled(feature string, options ...FeatureOption) api.Strate } func (uc *Client) isParentDependencySatisfied(feature *api.Feature, context context.Context) bool { + warnOnce := &WarnOnce{} + for _, parent := range *feature.Dependencies { parentToggle := uc.repository.getToggle(parent.Feature) if parentToggle == nil { + warnOnce.Warn("the parent toggle was not found in the cache, the evaluation of this dependency will always be false") return false } diff --git a/utils.go b/utils.go index 9e2eebf..8ba2c36 100644 --- a/utils.go +++ b/utils.go @@ -5,6 +5,7 @@ import ( "math/rand" "os" "os/user" + "sync" "time" ) @@ -43,3 +44,15 @@ func contains(arr []string, str string) bool { } return false } + +// WarnOnce is a type for handling warnings that should only be displayed once. +type WarnOnce struct { + once sync.Once +} + +// Warn logs the warning message once. +func (wo *WarnOnce) Warn(message string) { + wo.once.Do(func() { + fmt.Println("Warning:", message) + }) +}