Skip to content

Commit 60f89bf

Browse files
Return sentinel errors to help handling by callers (#58)
* return sentinel errors * chore: bump version --------- Co-authored-by: Oleksii Shmalko <[email protected]>
1 parent 1e1323b commit 60f89bf

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

eppoclient/configurationstore.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package eppoclient
22

33
import (
4-
"errors"
54
"sync/atomic"
65
)
76

@@ -50,7 +49,7 @@ func (c configuration) getBanditVariant(flagKey, variation string) (result bandi
5049
func (c configuration) getFlagConfiguration(key string) (flagConfiguration, error) {
5150
flag, ok := c.flags.Flags[key]
5251
if !ok {
53-
return flag, errors.New("flag configuration not found")
52+
return flag, ErrFlagConfigurationNotFound
5453
}
5554

5655
return flag, nil
@@ -59,7 +58,7 @@ func (c configuration) getFlagConfiguration(key string) (flagConfiguration, erro
5958
func (c configuration) getBanditConfiguration(key string) (banditConfiguration, error) {
6059
bandit, ok := c.bandits.Bandits[key]
6160
if !ok {
62-
return bandit, errors.New("bandit configuration not found")
61+
return bandit, ErrBanditConfigurationNotFound
6362
}
6463

6564
return bandit, nil

eppoclient/errors.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package eppoclient
2+
3+
import "errors"
4+
5+
var (
6+
ErrSubjectAllocation = errors.New("subject is not part of any allocation")
7+
ErrFlagNotEnabled = errors.New("the experiment or flag is not enabled")
8+
ErrFlagConfigurationNotFound = errors.New("flag configuration not found")
9+
ErrBanditConfigurationNotFound = errors.New("bandit configuration not found")
10+
)

eppoclient/evalflags.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package eppoclient
22

33
import (
4-
"errors"
54
"fmt"
65
"time"
76

@@ -18,7 +17,7 @@ func (flag flagConfiguration) verifyType(ty variationType) error {
1817

1918
func (flag flagConfiguration) eval(subjectKey string, subjectAttributes Attributes, applicationLogger applicationlogger.Logger) (interface{}, *AssignmentEvent, error) {
2019
if !flag.Enabled {
21-
return nil, nil, errors.New("the experiment or flag is not enabled")
20+
return nil, nil, ErrFlagNotEnabled
2221
}
2322

2423
now := time.Now()
@@ -34,7 +33,7 @@ func (flag flagConfiguration) eval(subjectKey string, subjectAttributes Attribut
3433
}
3534
}
3635
if allocation == nil || split == nil {
37-
return nil, nil, errors.New("subject is not part of any allocation")
36+
return nil, nil, ErrSubjectAllocation
3837
}
3938

4039
variation, ok := flag.Variations[split.VariationKey]

eppoclient/initclient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package eppoclient
44

55
import "net/http"
66

7-
var __version__ = "5.0.0"
7+
var __version__ = "5.1.0"
88

99
// InitClient is required to start polling of experiments configurations and create
1010
// an instance of EppoClient, which could be used to get assignments information.

0 commit comments

Comments
 (0)