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-12-12 09:00:16 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-12-14 14:04:57 +0300
commit2175c8a8f4519bc6a286eb289285e0bf720a67f5 (patch)
tree1774bc8af55c31cc7b03f385656c6d1296c779b3
parent4d1e05721d35c519810bc4332ce3b13e2df3ea34 (diff)
helper: Convert and drop usage of `ErrUnavailablef()`
Convert callers of `ErrUnavailablef()` to instead use the `structerr` package. Remove the now-unused function.
-rw-r--r--internal/gitaly/service/blob/get_blob.go9
-rw-r--r--internal/gitaly/service/blob/get_blobs.go11
-rw-r--r--internal/gitaly/service/commit/tree_entry.go4
-rw-r--r--internal/gitaly/service/smarthttp/receive_pack.go5
-rw-r--r--internal/gitaly/service/smarthttp/upload_pack.go7
-rw-r--r--internal/gitaly/service/smarthttp/upload_pack_test.go3
-rw-r--r--internal/gitaly/service/ssh/upload_pack.go2
-rw-r--r--internal/helper/error.go6
-rw-r--r--internal/helper/error_test.go5
9 files changed, 23 insertions, 29 deletions
diff --git a/internal/gitaly/service/blob/get_blob.go b/internal/gitaly/service/blob/get_blob.go
index b43b24023..c25b6b618 100644
--- a/internal/gitaly/service/blob/get_blob.go
+++ b/internal/gitaly/service/blob/get_blob.go
@@ -8,6 +8,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"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"
)
@@ -31,7 +32,7 @@ func (s *server) GetBlob(in *gitalypb.GetBlobRequest, stream gitalypb.BlobServic
if err != nil {
if catfile.IsNotFound(err) {
if err := stream.Send(&gitalypb.GetBlobResponse{}); err != nil {
- return helper.ErrUnavailablef("sending empty response: %w", err)
+ return structerr.NewUnavailable("sending empty response: %w", err)
}
return nil
}
@@ -40,7 +41,7 @@ func (s *server) GetBlob(in *gitalypb.GetBlobRequest, stream gitalypb.BlobServic
if blob.Type != "blob" {
if err := stream.Send(&gitalypb.GetBlobResponse{}); err != nil {
- return helper.ErrUnavailablef("sending empty response: %w", err)
+ return structerr.NewUnavailable("sending empty response: %w", err)
}
return nil
@@ -57,7 +58,7 @@ func (s *server) GetBlob(in *gitalypb.GetBlobRequest, stream gitalypb.BlobServic
if readLimit == 0 {
if err := stream.Send(firstMessage); err != nil {
- return helper.ErrUnavailablef("sending empty blob: %w", err)
+ return structerr.NewUnavailable("sending empty blob: %w", err)
}
return nil
@@ -75,7 +76,7 @@ func (s *server) GetBlob(in *gitalypb.GetBlobRequest, stream gitalypb.BlobServic
_, err = io.CopyN(sw, blob, readLimit)
if err != nil {
- return helper.ErrUnavailablef("send: %w", err)
+ return structerr.NewUnavailable("send: %w", err)
}
return nil
diff --git a/internal/gitaly/service/blob/get_blobs.go b/internal/gitaly/service/blob/get_blobs.go
index a38fc90c2..799d89fb5 100644
--- a/internal/gitaly/service/blob/get_blobs.go
+++ b/internal/gitaly/service/blob/get_blobs.go
@@ -9,6 +9,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"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"
)
@@ -46,7 +47,7 @@ func sendGetBlobsResponse(
if treeEntry == nil || len(treeEntry.Oid) == 0 {
if err := stream.Send(response); err != nil {
- return helper.ErrUnavailablef("send: %w", err)
+ return structerr.NewUnavailable("send: %w", err)
}
continue
@@ -60,7 +61,7 @@ func sendGetBlobsResponse(
response.Type = gitalypb.ObjectType_COMMIT
if err := stream.Send(response); err != nil {
- return helper.ErrUnavailablef("send: %w", err)
+ return structerr.NewUnavailable("send: %w", err)
}
continue
@@ -82,7 +83,7 @@ func sendGetBlobsResponse(
if response.Type != gitalypb.ObjectType_BLOB {
if err := stream.Send(response); err != nil {
- return helper.ErrUnavailablef("send: %w", err)
+ return structerr.NewUnavailable("send: %w", err)
}
continue
}
@@ -115,7 +116,7 @@ func sendBlobTreeEntry(
// blobObj.
if readLimit == 0 {
if err := stream.Send(response); err != nil {
- return helper.ErrUnavailablef("send: %w", err)
+ return structerr.NewUnavailable("send: %w", err)
}
return nil
}
@@ -147,7 +148,7 @@ func sendBlobTreeEntry(
_, err = io.CopyN(sw, blobObj, readLimit)
if err != nil {
- return helper.ErrUnavailablef("send: %w", err)
+ return structerr.NewUnavailable("send: %w", err)
}
return nil
diff --git a/internal/gitaly/service/commit/tree_entry.go b/internal/gitaly/service/commit/tree_entry.go
index 74827124e..cef7662e6 100644
--- a/internal/gitaly/service/commit/tree_entry.go
+++ b/internal/gitaly/service/commit/tree_entry.go
@@ -59,7 +59,7 @@ func sendTreeEntry(
}
if err := stream.Send(response); err != nil {
- return helper.ErrUnavailablef("sending response: %w", err)
+ return structerr.NewUnavailable("sending response: %w", err)
}
return nil
@@ -98,7 +98,7 @@ func sendTreeEntry(
}
if dataLength == 0 {
if err := stream.Send(response); err != nil {
- return helper.ErrUnavailablef("sending response: %w", err)
+ return structerr.NewUnavailable("sending response: %w", err)
}
return nil
diff --git a/internal/gitaly/service/smarthttp/receive_pack.go b/internal/gitaly/service/smarthttp/receive_pack.go
index a44469f5c..59af6df40 100644
--- a/internal/gitaly/service/smarthttp/receive_pack.go
+++ b/internal/gitaly/service/smarthttp/receive_pack.go
@@ -9,6 +9,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/voting"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -63,11 +64,11 @@ func (s *server) PostReceivePack(stream gitalypb.SmartHTTPService_PostReceivePac
git.WithConfig(config...),
)
if err != nil {
- return helper.ErrUnavailablef("spawning receive-pack: %w", err)
+ return structerr.NewUnavailable("spawning receive-pack: %w", err)
}
if err := cmd.Wait(); err != nil {
- return helper.ErrUnavailablef("waiting for receive-pack: %w", err)
+ return structerr.NewUnavailable("waiting for receive-pack: %w", err)
}
// In cases where all reference updates are rejected by git-receive-pack(1), we would end up
diff --git a/internal/gitaly/service/smarthttp/upload_pack.go b/internal/gitaly/service/smarthttp/upload_pack.go
index af64f5b03..385b13264 100644
--- a/internal/gitaly/service/smarthttp/upload_pack.go
+++ b/internal/gitaly/service/smarthttp/upload_pack.go
@@ -13,6 +13,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/sidechannel"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/structerr"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
)
@@ -152,13 +153,13 @@ func (s *server) runUploadPack(ctx context.Context, req basicPostUploadPackReque
Args: []string{repoPath},
}, commandOpts...)
if err != nil {
- return helper.ErrUnavailablef("spawning upload-pack: %w", err)
+ return structerr.NewUnavailable("spawning upload-pack: %w", err)
}
// Use a custom buffer size to minimize the number of system calls.
respBytes, err := io.CopyBuffer(stdout, cmd, make([]byte, 64*1024))
if err != nil {
- return helper.ErrUnavailablef("copying stdout from upload-pack: %w", err)
+ return structerr.NewUnavailable("copying stdout from upload-pack: %w", err)
}
if err := cmd.Wait(); err != nil {
@@ -171,7 +172,7 @@ func (s *server) runUploadPack(ctx context.Context, req basicPostUploadPackReque
return nil
}
- return helper.ErrUnavailablef("waiting for upload-pack: %w", err)
+ return structerr.NewUnavailable("waiting for upload-pack: %w", err)
}
ctxlogrus.Extract(ctx).WithField("request_sha", fmt.Sprintf("%x", h.Sum(nil))).WithField("response_bytes", respBytes).Info("request details")
diff --git a/internal/gitaly/service/smarthttp/upload_pack_test.go b/internal/gitaly/service/smarthttp/upload_pack_test.go
index a47938d7f..6b650e57b 100644
--- a/internal/gitaly/service/smarthttp/upload_pack_test.go
+++ b/internal/gitaly/service/smarthttp/upload_pack_test.go
@@ -23,6 +23,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/git/pktline"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/sidechannel"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/structerr"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testcfg"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testserver"
@@ -172,7 +173,7 @@ func testServerPostUploadPackGitConfigOptions(t *testing.T, ctx context.Context,
},
}
response, err := makeRequest(t, ctx, cfg.SocketPath, cfg.Auth.Token, rpcRequest, bytes.NewReader(requestBody.Bytes()))
- testhelper.RequireGrpcError(t, helper.ErrUnavailablef("running upload-pack: waiting for upload-pack: exit status 128"), err)
+ testhelper.RequireGrpcError(t, structerr.NewUnavailable("running upload-pack: waiting for upload-pack: exit status 128"), err)
// The failure message proves that upload-pack failed because of
// GitConfigOptions, and that proves that passing GitConfigOptions works.
diff --git a/internal/gitaly/service/ssh/upload_pack.go b/internal/gitaly/service/ssh/upload_pack.go
index 332572d6c..23e42ad7e 100644
--- a/internal/gitaly/service/ssh/upload_pack.go
+++ b/internal/gitaly/service/ssh/upload_pack.go
@@ -205,7 +205,7 @@ func (rf *largeBufferReaderFrom) ReadFrom(r io.Reader) (int64, error) {
func (s *server) SSHUploadPackWithSidechannel(ctx context.Context, req *gitalypb.SSHUploadPackWithSidechannelRequest) (*gitalypb.SSHUploadPackWithSidechannelResponse, error) {
conn, err := sidechannel.OpenSidechannel(ctx)
if err != nil {
- return nil, helper.ErrUnavailablef("opennig sidechannel: %w", err)
+ return nil, structerr.NewUnavailable("opennig sidechannel: %w", err)
}
defer conn.Close()
diff --git a/internal/helper/error.go b/internal/helper/error.go
index 718e0d55e..82b209743 100644
--- a/internal/helper/error.go
+++ b/internal/helper/error.go
@@ -45,12 +45,6 @@ func ErrFailedPreconditionf(format string, a ...interface{}) error {
return formatError(codes.FailedPrecondition, format, a...)
}
-// ErrUnavailablef wraps a formatted error with codes.Unavailable, unless the
-// formatted error is a wrapped gRPC error.
-func ErrUnavailablef(format string, a ...interface{}) error {
- return formatError(codes.Unavailable, format, a...)
-}
-
// ErrPermissionDeniedf wraps a formatted error with codes.PermissionDenied, unless the formatted
// error is a wrapped gRPC error.
func ErrPermissionDeniedf(format string, a ...interface{}) error {
diff --git a/internal/helper/error_test.go b/internal/helper/error_test.go
index ab4664fa1..65a625297 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: "ErrUnavailablef",
- errorf: ErrUnavailablef,
- expectedCode: codes.Unavailable,
- },
- {
desc: "ErrAbortedf",
errorf: ErrAbortedf,
expectedCode: codes.Aborted,