Skip to content

Commit

Permalink
Dont error on disabled flag (#382)
Browse files Browse the repository at this point in the history
* Dont error on disabled flag

* Update CHANGELOG
  • Loading branch information
markphelps authored Feb 10, 2021
1 parent 2f34184 commit 061dbcb
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Changed

* Don't error on evaluating flags that are disabled, return no match instead [https:/markphelps/flipt/pull/382](https:/markphelps/flipt/pull/382)

## [v1.1.0](https:/markphelps/flipt/releases/tag/v1.1.0) - 2021-01-15

### Changed
Expand Down
12 changes: 0 additions & 12 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ func (e ErrInvalid) Error() string {
return string(e)
}

// ErrDisabled represents a disabled flag
type ErrDisabled string

// ErrDisabledf creates an ErrDisabled using a custom format
func ErrDisabledf(format string, args ...interface{}) error {
return ErrDisabled(fmt.Sprintf(format, args...))
}

func (e ErrDisabled) Error() string {
return string(e)
}

// ErrValidation is a validation error for a specific field and reason
type ErrValidation struct {
field string
Expand Down
5 changes: 3 additions & 2 deletions rpc/flipt.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rpc/flipt_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions server/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package server

import (
"context"
"errors"
"fmt"
"hash/crc32"
"sort"
Expand Down Expand Up @@ -70,10 +69,9 @@ func (s *Server) batchEvaluate(ctx context.Context, r *flipt.BatchEvaluationRequ
Responses: make([]*flipt.EvaluationResponse, 0, len(r.GetRequests())),
}

var errd errs.ErrDisabled
for _, flag := range r.GetRequests() {
f, err := s.evaluate(ctx, flag)
if err != nil && !errors.As(err, &errd) {
if err != nil {
return &res, err
}
f.RequestId = ""
Expand Down Expand Up @@ -102,7 +100,8 @@ func (s *Server) evaluate(ctx context.Context, r *flipt.EvaluationRequest) (*fli
}

if !flag.Enabled {
return resp, errs.ErrDisabledf("flag %q is disabled", r.FlagKey)
resp.Match = false
return resp, nil
}

rules, err := s.store.GetEvaluationRules(ctx, r.FlagKey)
Expand Down
3 changes: 1 addition & 2 deletions server/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ func TestEvaluate_FlagDisabled(t *testing.T) {
},
})

require.Error(t, err)
assert.EqualError(t, err, "flag \"foo\" is disabled")
require.NoError(t, err)
assert.False(t, resp.Match)
}

Expand Down

0 comments on commit 061dbcb

Please sign in to comment.