diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c26fb2599..8d20e2fe90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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://github.com/markphelps/flipt/pull/382](https://github.com/markphelps/flipt/pull/382) + ## [v1.1.0](https://github.com/markphelps/flipt/releases/tag/v1.1.0) - 2021-01-15 ### Changed diff --git a/errors/errors.go b/errors/errors.go index 8466697113..7434e5533b 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -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 diff --git a/rpc/flipt.pb.go b/rpc/flipt.pb.go index bafd97415d..ac69d7970a 100644 --- a/rpc/flipt.pb.go +++ b/rpc/flipt.pb.go @@ -7,14 +7,15 @@ package flipt import ( + reflect "reflect" + sync "sync" + proto "github.com/golang/protobuf/proto" _ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" emptypb "google.golang.org/protobuf/types/known/emptypb" timestamppb "google.golang.org/protobuf/types/known/timestamppb" - reflect "reflect" - sync "sync" ) const ( diff --git a/rpc/flipt_grpc.pb.go b/rpc/flipt_grpc.pb.go index b688ba3df1..3f0cede2f1 100644 --- a/rpc/flipt_grpc.pb.go +++ b/rpc/flipt_grpc.pb.go @@ -4,6 +4,7 @@ package flipt import ( context "context" + grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" diff --git a/server/evaluator.go b/server/evaluator.go index 5a38a0fdaf..cc649755e1 100644 --- a/server/evaluator.go +++ b/server/evaluator.go @@ -2,7 +2,6 @@ package server import ( "context" - "errors" "fmt" "hash/crc32" "sort" @@ -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 = "" @@ -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) diff --git a/server/evaluator_test.go b/server/evaluator_test.go index 1ac2639dc4..452c537f6c 100644 --- a/server/evaluator_test.go +++ b/server/evaluator_test.go @@ -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) }