diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-12-14 14:05:21 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-12-14 14:05:21 +0300 |
commit | f21f0c4c916f149b234ae39a23a3bb9ce8c5c346 (patch) | |
tree | 59ac9d67bab1ede96f252b02e858ca44ef1f9f53 | |
parent | 2175c8a8f4519bc6a286eb289285e0bf720a67f5 (diff) |
helper: Convert and drop usage of `ErrAbortedf()`
Convert callers of `ErrAbortedf()` to instead use the
`structerr` package. Remove the now-unused function.
-rw-r--r-- | internal/gitaly/service/hook/reference_transaction.go | 3 | ||||
-rw-r--r-- | internal/gitaly/service/operations/squash.go | 4 | ||||
-rw-r--r-- | internal/gitaly/service/operations/squash_test.go | 5 | ||||
-rw-r--r-- | internal/gitaly/service/repository/fetch_remote.go | 3 | ||||
-rw-r--r-- | internal/gitaly/service/smarthttp/receive_pack.go | 2 | ||||
-rw-r--r-- | internal/gitaly/service/ssh/receive_pack.go | 2 | ||||
-rw-r--r-- | internal/helper/error.go | 6 | ||||
-rw-r--r-- | internal/helper/error_test.go | 7 |
8 files changed, 12 insertions, 20 deletions
diff --git a/internal/gitaly/service/hook/reference_transaction.go b/internal/gitaly/service/hook/reference_transaction.go index 68e64982f..16bef56b9 100644 --- a/internal/gitaly/service/hook/reference_transaction.go +++ b/internal/gitaly/service/hook/reference_transaction.go @@ -7,6 +7,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service" "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/v15/internal/helper" + "gitlab.com/gitlab-org/gitaly/v15/internal/structerr" "gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/v15/streamio" ) @@ -50,7 +51,7 @@ func (s *server) ReferenceTransactionHook(stream gitalypb.HookService_ReferenceT ); err != nil { switch { case errors.Is(err, transaction.ErrTransactionAborted): - return helper.ErrAbortedf("reference-transaction hook: %w", err) + return structerr.NewAborted("reference-transaction hook: %w", err) case errors.Is(err, transaction.ErrTransactionStopped): return helper.ErrFailedPreconditionf("reference-transaction hook: %w", err) default: diff --git a/internal/gitaly/service/operations/squash.go b/internal/gitaly/service/operations/squash.go index 5219bc579..9cdb260be 100644 --- a/internal/gitaly/service/operations/squash.go +++ b/internal/gitaly/service/operations/squash.go @@ -188,7 +188,7 @@ func (s *Server) userSquash(ctx context.Context, req *gitalypb.UserSquashRequest voting.VoteFromData([]byte(commitID)), voting.Prepared, ); err != nil { - return "", helper.ErrAbortedf("preparatory vote on squashed commit: %w", err) + return "", structerr.NewAborted("preparatory vote on squashed commit: %w", err) } if err := quarantineDir.Migrate(); err != nil { @@ -201,7 +201,7 @@ func (s *Server) userSquash(ctx context.Context, req *gitalypb.UserSquashRequest voting.VoteFromData([]byte(commitID)), voting.Committed, ); err != nil { - return "", helper.ErrAbortedf("committing vote on squashed commit: %w", err) + return "", structerr.NewAborted("committing vote on squashed commit: %w", err) } return commitID, nil diff --git a/internal/gitaly/service/operations/squash_test.go b/internal/gitaly/service/operations/squash_test.go index f3cd29017..4d24537ab 100644 --- a/internal/gitaly/service/operations/squash_test.go +++ b/internal/gitaly/service/operations/squash_test.go @@ -18,6 +18,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v15/internal/helper" "gitlab.com/gitlab-org/gitaly/v15/internal/helper/text" "gitlab.com/gitlab-org/gitaly/v15/internal/metadata" + "gitlab.com/gitlab-org/gitaly/v15/internal/structerr" "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testserver" "gitlab.com/gitlab-org/gitaly/v15/internal/transaction/txinfo" @@ -133,7 +134,7 @@ func TestUserSquash_transactional(t *testing.T) { voteFn: func(ctx context.Context, tx txinfo.Transaction, vote voting.Vote, phase voting.Phase) error { return errors.New("vote failed") }, - expectedErr: helper.ErrAbortedf("preparatory vote on squashed commit: vote failed"), + expectedErr: structerr.NewAborted("preparatory vote on squashed commit: vote failed"), expectedVotes: []voting.Vote{ squashedCommitVote, }, @@ -147,7 +148,7 @@ func TestUserSquash_transactional(t *testing.T) { } return nil }, - expectedErr: helper.ErrAbortedf("committing vote on squashed commit: vote failed"), + expectedErr: structerr.NewAborted("committing vote on squashed commit: vote failed"), expectedVotes: []voting.Vote{ squashedCommitVote, squashedCommitVote, diff --git a/internal/gitaly/service/repository/fetch_remote.go b/internal/gitaly/service/repository/fetch_remote.go index c1d50f796..05ee07307 100644 --- a/internal/gitaly/service/repository/fetch_remote.go +++ b/internal/gitaly/service/repository/fetch_remote.go @@ -12,6 +12,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service" "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/v15/internal/helper" + "gitlab.com/gitlab-org/gitaly/v15/internal/structerr" "gitlab.com/gitlab-org/gitaly/v15/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/v15/internal/transaction/voting" "gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb" @@ -125,7 +126,7 @@ func (s *server) FetchRemote(ctx context.Context, req *gitalypb.FetchRemoteReque return s.txManager.Vote(ctx, tx, vote, voting.UnknownPhase) }); err != nil { - return nil, helper.ErrAbortedf("failed vote on refs: %w", err) + return nil, structerr.NewAborted("failed vote on refs: %w", err) } out := &gitalypb.FetchRemoteResponse{TagsChanged: true} diff --git a/internal/gitaly/service/smarthttp/receive_pack.go b/internal/gitaly/service/smarthttp/receive_pack.go index 59af6df40..1fef1da64 100644 --- a/internal/gitaly/service/smarthttp/receive_pack.go +++ b/internal/gitaly/service/smarthttp/receive_pack.go @@ -88,7 +88,7 @@ func (s *server) PostReceivePack(stream gitalypb.SmartHTTPService_PostReceivePac // To avoid this error being presented to the end user, ignore it when the // transaction was stopped. if !errors.Is(err, transaction.ErrTransactionStopped) { - return helper.ErrAbortedf("final transactional vote: %w", err) + return structerr.NewAborted("final transactional vote: %w", err) } } diff --git a/internal/gitaly/service/ssh/receive_pack.go b/internal/gitaly/service/ssh/receive_pack.go index 3632404af..27825f514 100644 --- a/internal/gitaly/service/ssh/receive_pack.go +++ b/internal/gitaly/service/ssh/receive_pack.go @@ -131,7 +131,7 @@ func (s *server) sshReceivePack(stream gitalypb.SSHService_SSHReceivePackServer, // To avoid this error being presented to the end user, ignore it when the // transaction was stopped. if !errors.Is(err, transaction.ErrTransactionStopped) { - return helper.ErrAbortedf("final transactional vote: %w", err) + return structerr.NewAborted("final transactional vote: %w", err) } } diff --git a/internal/helper/error.go b/internal/helper/error.go index 82b209743..4c4fd20ac 100644 --- a/internal/helper/error.go +++ b/internal/helper/error.go @@ -57,12 +57,6 @@ func ErrAlreadyExistsf(format string, a ...interface{}) error { return formatError(codes.AlreadyExists, format, a...) } -// ErrAbortedf wraps a formatted error with codes.Aborted, unless the formatted error is a wrapped -// gRPC error. -func ErrAbortedf(format string, a ...interface{}) error { - return formatError(codes.Aborted, format, a...) -} - // ErrDataLossf wraps a formatted error with codes.DataLoss, unless the formatted error is a wrapped // gRPC error. func ErrDataLossf(format string, a ...interface{}) error { diff --git a/internal/helper/error_test.go b/internal/helper/error_test.go index 65a625297..c4f4e7841 100644 --- a/internal/helper/error_test.go +++ b/internal/helper/error_test.go @@ -45,11 +45,6 @@ func TestErrorf(t *testing.T) { expectedCode: codes.NotFound, }, { - desc: "ErrAbortedf", - errorf: ErrAbortedf, - expectedCode: codes.Aborted, - }, - { desc: "ErrDataLossf", errorf: ErrDataLossf, expectedCode: codes.DataLoss, @@ -221,7 +216,7 @@ func TestGrpcCode(t *testing.T) { exp: codes.NotFound, }, "double helper wrapped status": { - in: ErrAbortedf("outer: %w", fmt.Errorf("context: %w", ErrNotFoundf(""))), + in: ErrFailedPreconditionf("outer: %w", fmt.Errorf("context: %w", ErrNotFoundf(""))), exp: codes.NotFound, }, "nil input": { |