Skip to content

Commit

Permalink
fix: add warning
Browse files Browse the repository at this point in the history
  • Loading branch information
FredrikOseberg committed Sep 27, 2023
1 parent b2f726b commit e01a9cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
13 changes: 13 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/rand"
"os"
"os/user"
"sync"
"time"
)

Expand Down Expand Up @@ -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)
})
}

0 comments on commit e01a9cd

Please sign in to comment.