Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-07 15:38:28 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-07 15:52:09 +0300
commitf1cc331e80b2d94f6917ebd3923f0cb09475ff1f (patch)
tree980d8c1a7e89ce9ee8d418f5be63541717f66bb7
parent860328e692a2707c459daec873e3e03935372925 (diff)
operations: Modernize error messages returned by UserDeleteBranch
Modernize error messages returned by UserDeleteBranch to match our modern coding style more closely.
-rw-r--r--internal/gitaly/service/operations/branches.go11
-rw-r--r--internal/gitaly/service/operations/branches_test.go6
2 files changed, 9 insertions, 8 deletions
diff --git a/internal/gitaly/service/operations/branches.go b/internal/gitaly/service/operations/branches.go
index b209c0bf1..db5757eb3 100644
--- a/internal/gitaly/service/operations/branches.go
+++ b/internal/gitaly/service/operations/branches.go
@@ -6,6 +6,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/updateref"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@@ -147,18 +148,18 @@ func (s *Server) UserUpdateBranch(ctx context.Context, req *gitalypb.UserUpdateB
// hooks and contacts Rails to verify that the user is indeed allowed to delete that branch.
func (s *Server) UserDeleteBranch(ctx context.Context, req *gitalypb.UserDeleteBranchRequest) (*gitalypb.UserDeleteBranchResponse, error) {
if len(req.BranchName) == 0 {
- return nil, status.Errorf(codes.InvalidArgument, "Bad Request (empty branch name)")
+ return nil, helper.ErrInvalidArgumentf("bad request: empty branch name")
}
if req.User == nil {
- return nil, status.Errorf(codes.InvalidArgument, "Bad Request (empty user)")
+ return nil, helper.ErrInvalidArgumentf("bad request: empty user")
}
referenceName := git.NewReferenceNameFromBranchName(string(req.BranchName))
referenceValue, err := s.localrepo(req.GetRepository()).ResolveRevision(ctx, referenceName.Revision())
if err != nil {
- return nil, status.Errorf(codes.FailedPrecondition, "branch not found: %s", req.BranchName)
+ return nil, helper.ErrFailedPreconditionf("branch not found: %q", req.BranchName)
}
if err := s.updateReferenceWithHooks(ctx, req.Repository, req.User, nil, referenceName, git.ZeroOID, referenceValue); err != nil {
@@ -171,10 +172,10 @@ func (s *Server) UserDeleteBranch(ctx context.Context, req *gitalypb.UserDeleteB
var updateRefError updateref.Error
if errors.As(err, &updateRefError) {
- return nil, status.Error(codes.FailedPrecondition, err.Error())
+ return nil, helper.ErrFailedPrecondition(err)
}
- return nil, err
+ return nil, helper.ErrInternalf("deleting reference: %w", err)
}
return &gitalypb.UserDeleteBranchResponse{}, nil
diff --git a/internal/gitaly/service/operations/branches_test.go b/internal/gitaly/service/operations/branches_test.go
index cc077102c..65ed449e9 100644
--- a/internal/gitaly/service/operations/branches_test.go
+++ b/internal/gitaly/service/operations/branches_test.go
@@ -529,7 +529,7 @@ func TestFailedUserDeleteBranchDueToValidation(t *testing.T) {
BranchName: []byte("does-matter-the-name-if-user-is-empty"),
},
response: nil,
- err: status.Error(codes.InvalidArgument, "Bad Request (empty user)"),
+ err: status.Error(codes.InvalidArgument, "bad request: empty user"),
},
{
desc: "empty branch name",
@@ -538,7 +538,7 @@ func TestFailedUserDeleteBranchDueToValidation(t *testing.T) {
User: gittest.TestUser,
},
response: nil,
- err: status.Error(codes.InvalidArgument, "Bad Request (empty branch name)"),
+ err: status.Error(codes.InvalidArgument, "bad request: empty branch name"),
},
{
desc: "non-existent branch name",
@@ -548,7 +548,7 @@ func TestFailedUserDeleteBranchDueToValidation(t *testing.T) {
BranchName: []byte("i-do-not-exist"),
},
response: nil,
- err: status.Errorf(codes.FailedPrecondition, "branch not found: %s", "i-do-not-exist"),
+ err: status.Errorf(codes.FailedPrecondition, "branch not found: %q", "i-do-not-exist"),
},
}