Skip to content

Commit

Permalink
Merge pull request #2801 from thaJeztah/18.09_backport_change_error_m…
Browse files Browse the repository at this point in the history
…essage

[18.09 backport] Include old error-message for backward compatibility
  • Loading branch information
dperny authored Jan 7, 2019
2 parents d61ff76 + 3b1fe92 commit 19a6d36
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion manager/controlapi/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,10 @@ func (s *Server) CreateService(ctx context.Context, request *api.CreateServiceRe
})
switch err {
case store.ErrNameConflict:
return nil, status.Errorf(codes.AlreadyExists, "service %s already exists", request.Spec.Annotations.Name)
// Enhance the name-confict error to include the service name. The original
// `ErrNameConflict` error-message is included for backward-compatibility
// with older consumers of the API performing string-matching.
return nil, status.Errorf(codes.AlreadyExists, "%s: service %s already exists", err.Error(), request.Spec.Annotations.Name)
case nil:
return &api.CreateServiceResponse{Service: service}, nil
default:
Expand Down
4 changes: 4 additions & 0 deletions manager/controlapi/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,10 @@ func TestCreateService(t *testing.T) {
r, err = ts.Client.CreateService(context.Background(), &api.CreateServiceRequest{Spec: spec})
assert.Error(t, err)
assert.Equal(t, codes.AlreadyExists, testutils.ErrorCode(err))

// Make sure the error contains "name conflicts with an existing object" for
// backward-compatibility with older clients doing string-matching...
assert.Contains(t, err.Error(), "name conflicts with an existing object")
}

func TestSecretValidation(t *testing.T) {
Expand Down

0 comments on commit 19a6d36

Please sign in to comment.