diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-08-31 11:55:41 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-09-08 12:32:34 +0300 |
commit | a05a8088627e3e5d4902676dc06af345559b20cb (patch) | |
tree | db61e631a6dc67f380cb30442a3d53cca223e1cf | |
parent | 3c206210aa1ec0a0142e58f41a08f92621d64b19 (diff) |
repository: Convert ApplyGitattributes to use helpers for gRPC errors
Use helper functions to create errors with gRPC status codes instead of
using the open-coded variants.
-rw-r--r-- | internal/gitaly/service/repository/apply_gitattributes.go | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/internal/gitaly/service/repository/apply_gitattributes.go b/internal/gitaly/service/repository/apply_gitattributes.go index 9dbbdbc7c..818a45866 100644 --- a/internal/gitaly/service/repository/apply_gitattributes.go +++ b/internal/gitaly/service/repository/apply_gitattributes.go @@ -12,11 +12,10 @@ import ( "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/v14/internal/git" "gitlab.com/gitlab-org/gitaly/v14/internal/git/catfile" + "gitlab.com/gitlab-org/gitaly/v14/internal/helper" "gitlab.com/gitlab-org/gitaly/v14/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/v14/internal/transaction/voting" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) const attributesFileMode os.FileMode = 0o644 @@ -28,7 +27,7 @@ func (s *server) applyGitattributes(ctx context.Context, c catfile.Batch, repoPa _, err := c.Info(ctx, git.Revision(revision)) if err != nil { if catfile.IsNotFound(err) { - return status.Errorf(codes.InvalidArgument, "Revision doesn't exist") + return helper.ErrInvalidArgumentf("revision does not exist") } return err @@ -61,7 +60,7 @@ func (s *server) applyGitattributes(ctx context.Context, c catfile.Batch, repoPa tempFile, err := ioutil.TempFile(infoPath, "attributes") if err != nil { - return status.Errorf(codes.Internal, "ApplyGitAttributes: creating temp file: %v", err) + return helper.ErrInternalf("creating temporary gitattributes file: %w", err) } defer func() { if err := os.Remove(tempFile.Name()); err != nil && !errors.Is(err, os.ErrNotExist) { @@ -128,7 +127,7 @@ func (s *server) ApplyGitattributes(ctx context.Context, in *gitalypb.ApplyGitat } if err := git.ValidateRevision(in.GetRevision()); err != nil { - return nil, status.Errorf(codes.InvalidArgument, "ApplyGitAttributes: revision: %v", err) + return nil, helper.ErrInvalidArgumentf("revision: %v", err) } c, err := s.catfileCache.BatchProcess(ctx, repo) |