Skip to content

Commit a779e3a

Browse files
authored
Merge pull request #27 from drone/FFM-1108
[FFM-1108]: Add a log when the segment in variation map is invalid
2 parents 0be7fa1 + f310173 commit a779e3a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

evaluation/feature.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"reflect"
77
"strconv"
88

9+
"github.com/labstack/gommon/log"
10+
911
"github.com/drone/ff-golang-server-sdk/types"
1012
)
1113

@@ -227,11 +229,15 @@ func (fc FeatureConfig) GetVariationName(target *Target) string {
227229

228230
if variationMap.TargetSegments != nil {
229231
for _, segmentIdentifier := range variationMap.TargetSegments {
230-
segment := fc.Segments[segmentIdentifier]
231-
if segment.Included != nil {
232-
for _, t := range segment.Included {
233-
if t == target.Identifier {
234-
return variationMap.Variation
232+
segment, ok := fc.Segments[segmentIdentifier]
233+
if !ok {
234+
log.Error("The segment in variation map is invalid")
235+
} else {
236+
if segment.Included != nil {
237+
for _, t := range segment.Included {
238+
if t == target.Identifier {
239+
return variationMap.Variation
240+
}
235241
}
236242
}
237243
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/hashicorp/golang-lru v0.5.4
1212
github.com/jarcoal/httpmock v1.0.8
1313
github.com/json-iterator/go v1.1.10
14+
github.com/labstack/gommon v0.3.0 // indirect
1415
github.com/mitchellh/go-homedir v1.1.0
1516
github.com/mitchellh/mapstructure v1.3.3
1617
github.com/r3labs/sse v0.0.0-20201126193848-34e640891548

0 commit comments

Comments
 (0)