diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-12-19 12:19:28 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-12-19 14:51:11 +0300 |
commit | 0e11d14d78da343851ea8ba0b92af51a9c88cc4a (patch) | |
tree | 68249ae434d572f0814b84f9c46c07e809918faf /internal/praefect | |
parent | 38812995ea07e43b12b4151c24bf6b960a70f74d (diff) |
helper: Replace `helper.ErrInternalf()` with `structerr` package
Replace calls to `helper.ErrInternalf()` with `structerr.NewInternal()`
and remove the former function.
Diffstat (limited to 'internal/praefect')
-rw-r--r-- | internal/praefect/coordinator.go | 6 | ||||
-rw-r--r-- | internal/praefect/middleware/errorhandler_test.go | 6 | ||||
-rw-r--r-- | internal/praefect/rename_repository.go | 2 | ||||
-rw-r--r-- | internal/praefect/server_test.go | 12 | ||||
-rw-r--r-- | internal/praefect/service/info/metadata.go | 5 | ||||
-rw-r--r-- | internal/praefect/service/info/replication_factor.go | 3 | ||||
-rw-r--r-- | internal/praefect/service/info/repositories.go | 6 | ||||
-rw-r--r-- | internal/praefect/service/info/server.go | 3 | ||||
-rw-r--r-- | internal/praefect/service/transaction/server.go | 4 |
9 files changed, 25 insertions, 22 deletions
diff --git a/internal/praefect/coordinator.go b/internal/praefect/coordinator.go index 395e42c26..0c6ecadc6 100644 --- a/internal/praefect/coordinator.go +++ b/internal/praefect/coordinator.go @@ -699,7 +699,7 @@ func (c *Coordinator) StreamDirector(ctx context.Context, fullMethodName string, return c.directStorageScopedMessage(ctx, mi, m) } - return nil, helper.ErrInternalf("rpc with undefined scope %q", mi.Scope) + return nil, structerr.NewInternal("rpc with undefined scope %q", mi.Scope) } func (c *Coordinator) directStorageScopedMessage(ctx context.Context, mi protoregistry.MethodInfo, msg proto.Message) (*proxy.StreamParameters, error) { @@ -730,7 +730,7 @@ func (c *Coordinator) accessorStorageStreamParameters(ctx context.Context, mi pr if errors.Is(err, nodes.ErrVirtualStorageNotExist) { return nil, helper.ErrInvalidArgumentf("%w", err) } - return nil, helper.ErrInternalf("accessor storage scoped: route storage accessor %q: %w", virtualStorage, err) + return nil, structerr.NewInternal("accessor storage scoped: route storage accessor %q: %w", virtualStorage, err) } node.addLogFields(ctx) @@ -758,7 +758,7 @@ func (c *Coordinator) mutatorStorageStreamParameters(ctx context.Context, mi pro if errors.Is(err, nodes.ErrVirtualStorageNotExist) { return nil, helper.ErrInvalidArgumentf("%w", err) } - return nil, helper.ErrInternalf("mutator storage scoped: get shard %q: %w", virtualStorage, err) + return nil, structerr.NewInternal("mutator storage scoped: get shard %q: %w", virtualStorage, err) } route.addLogFields(ctx) diff --git a/internal/praefect/middleware/errorhandler_test.go b/internal/praefect/middleware/errorhandler_test.go index bf186ef9a..a57463063 100644 --- a/internal/praefect/middleware/errorhandler_test.go +++ b/internal/praefect/middleware/errorhandler_test.go @@ -10,10 +10,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/v15/internal/helper" "gitlab.com/gitlab-org/gitaly/v15/internal/praefect/grpc-proxy/proxy" "gitlab.com/gitlab-org/gitaly/v15/internal/praefect/nodes/tracker" "gitlab.com/gitlab-org/gitaly/v15/internal/praefect/protoregistry" + "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/proto/go/gitalypb" @@ -27,7 +27,7 @@ type repositoryService struct { func (s *repositoryService) RepositoryExists(ctx context.Context, req *gitalypb.RepositoryExistsRequest) (*gitalypb.RepositoryExistsResponse, error) { if req.GetRepository() == nil { - return nil, helper.ErrInternalf("error") + return nil, structerr.NewInternal("error") } return &gitalypb.RepositoryExistsResponse{}, nil @@ -35,7 +35,7 @@ func (s *repositoryService) RepositoryExists(ctx context.Context, req *gitalypb. func (s *repositoryService) WriteRef(ctx context.Context, req *gitalypb.WriteRefRequest) (*gitalypb.WriteRefResponse, error) { if req.GetRepository() == nil { - return nil, helper.ErrInternalf("error") + return nil, structerr.NewInternal("error") } return &gitalypb.WriteRefResponse{}, nil diff --git a/internal/praefect/rename_repository.go b/internal/praefect/rename_repository.go index 7433c6fb0..eb52b08cb 100644 --- a/internal/praefect/rename_repository.go +++ b/internal/praefect/rename_repository.go @@ -70,7 +70,7 @@ func RenameRepositoryHandler(virtualStoragesNames []string, rs datastore.Reposit return structerr.NewAlreadyExists("target repo exists already") } - return helper.ErrInternalf("%w", err) + return structerr.NewInternal("%w", err) } return stream.SendMsg(&gitalypb.RenameRepositoryResponse{}) diff --git a/internal/praefect/server_test.go b/internal/praefect/server_test.go index 1eca3fe99..91134c591 100644 --- a/internal/praefect/server_test.go +++ b/internal/praefect/server_test.go @@ -735,11 +735,11 @@ func (m *mockSmartHTTP) PostReceivePack(stream gitalypb.SmartHTTPService_PostRec if errors.Is(err, io.EOF) { break } - return helper.ErrInternalf("%w", err) + return structerr.NewInternal("%w", err) } if err := stream.Send(&gitalypb.PostReceivePackResponse{Data: req.GetData()}); err != nil { - return helper.ErrInternalf("%w", err) + return structerr.NewInternal("%w", err) } } @@ -747,12 +747,12 @@ func (m *mockSmartHTTP) PostReceivePack(stream gitalypb.SmartHTTPService_PostRec tx, err := txinfo.TransactionFromContext(ctx) if err != nil { - return helper.ErrInternalf("%w", err) + return structerr.NewInternal("%w", err) } vote := voting.VoteFromData([]byte{}) if err := m.txMgr.VoteTransaction(ctx, tx.ID, tx.Node, vote); err != nil { - return helper.ErrInternalf("%w", err) + return structerr.NewInternal("%w", err) } return nil @@ -902,7 +902,7 @@ func TestErrorThreshold(t *testing.T) { } if md.Get("bad-header")[0] == "true" { - return nil, helper.ErrInternalf("something went wrong") + return nil, structerr.NewInternal("something went wrong") } return &gitalypb.ReplicateRepositoryResponse{}, nil @@ -914,7 +914,7 @@ func TestErrorThreshold(t *testing.T) { } if md.Get("bad-header")[0] == "true" { - return nil, helper.ErrInternalf("something went wrong") + return nil, structerr.NewInternal("something went wrong") } return &gitalypb.RepositoryExistsResponse{}, nil diff --git a/internal/praefect/service/info/metadata.go b/internal/praefect/service/info/metadata.go index 30ee9e7c4..91d49d4aa 100644 --- a/internal/praefect/service/info/metadata.go +++ b/internal/praefect/service/info/metadata.go @@ -7,6 +7,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v15/internal/helper" "gitlab.com/gitlab-org/gitaly/v15/internal/praefect/commonerr" "gitlab.com/gitlab-org/gitaly/v15/internal/praefect/datastore" + "gitlab.com/gitlab-org/gitaly/v15/internal/structerr" "gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -24,7 +25,7 @@ func (s *Server) GetRepositoryMetadata(ctx context.Context, req *gitalypb.GetRep return s.rs.GetRepositoryMetadataByPath(ctx, query.Path.VirtualStorage, query.Path.RelativePath) } default: - return nil, helper.ErrInternalf("unknown query type: %T", query) + return nil, structerr.NewInternal("unknown query type: %T", query) } metadata, err := getMetadata() @@ -33,7 +34,7 @@ func (s *Server) GetRepositoryMetadata(ctx context.Context, req *gitalypb.GetRep return nil, helper.ErrNotFoundf("%w", err) } - return nil, helper.ErrInternalf("get metadata: %w", err) + return nil, structerr.NewInternal("get metadata: %w", err) } replicas := make([]*gitalypb.GetRepositoryMetadataResponse_Replica, 0, len(metadata.Replicas)) diff --git a/internal/praefect/service/info/replication_factor.go b/internal/praefect/service/info/replication_factor.go index d8a3e7f08..9f799bd26 100644 --- a/internal/praefect/service/info/replication_factor.go +++ b/internal/praefect/service/info/replication_factor.go @@ -7,6 +7,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v15/internal/helper" "gitlab.com/gitlab-org/gitaly/v15/internal/praefect/datastore" + "gitlab.com/gitlab-org/gitaly/v15/internal/structerr" "gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb" ) @@ -19,7 +20,7 @@ func (s *Server) SetReplicationFactor(ctx context.Context, req *gitalypb.SetRepl return nil, helper.ErrInvalidArgumentf("%w", err) } - return nil, helper.ErrInternalf("%w", err) + return nil, structerr.NewInternal("%w", err) } return resp, nil diff --git a/internal/praefect/service/info/repositories.go b/internal/praefect/service/info/repositories.go index 53e901328..1d8f7def0 100644 --- a/internal/praefect/service/info/repositories.go +++ b/internal/praefect/service/info/repositories.go @@ -4,8 +4,8 @@ import ( "context" "fmt" - "gitlab.com/gitlab-org/gitaly/v15/internal/helper" "gitlab.com/gitlab-org/gitaly/v15/internal/praefect/config" + "gitlab.com/gitlab-org/gitaly/v15/internal/structerr" "gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb" "golang.org/x/sync/errgroup" ) @@ -56,7 +56,7 @@ func (s *Server) RepositoryReplicas(ctx context.Context, in *gitalypb.Repository var resp gitalypb.RepositoryReplicasResponse if resp.Primary, err = s.getRepositoryDetails(ctx, virtualStorage, primary, relativePath, replicaPath); err != nil { - return nil, helper.ErrInternalf("%w", err) + return nil, structerr.NewInternal("%w", err) } resp.Replicas = make([]*gitalypb.RepositoryReplicasResponse_RepositoryDetails, len(secondaries)) @@ -74,7 +74,7 @@ func (s *Server) RepositoryReplicas(ctx context.Context, in *gitalypb.Repository } if err := g.Wait(); err != nil { - return nil, helper.ErrInternalf("%w", err) + return nil, structerr.NewInternal("%w", err) } return &resp, nil diff --git a/internal/praefect/service/info/server.go b/internal/praefect/service/info/server.go index b6ea956a8..5b5ba0f69 100644 --- a/internal/praefect/service/info/server.go +++ b/internal/praefect/service/info/server.go @@ -9,6 +9,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v15/internal/praefect/config" "gitlab.com/gitlab-org/gitaly/v15/internal/praefect/datastore" "gitlab.com/gitlab-org/gitaly/v15/internal/praefect/service" + "gitlab.com/gitlab-org/gitaly/v15/internal/structerr" "gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb" ) @@ -84,7 +85,7 @@ func (s *Server) SetAuthoritativeStorage(ctx context.Context, req *gitalypb.SetA return nil, helper.ErrInvalidArgumentf("repository %q does not exist on virtual storage %q", req.RelativePath, req.VirtualStorage) } - return nil, helper.ErrInternalf("%w", err) + return nil, structerr.NewInternal("%w", err) } return &gitalypb.SetAuthoritativeStorageResponse{}, nil diff --git a/internal/praefect/service/transaction/server.go b/internal/praefect/service/transaction/server.go index ca099d771..a2cdb7848 100644 --- a/internal/praefect/service/transaction/server.go +++ b/internal/praefect/service/transaction/server.go @@ -48,7 +48,7 @@ func (s *Server) VoteTransaction(ctx context.Context, in *gitalypb.VoteTransacti State: gitalypb.VoteTransactionResponse_ABORT, }, nil default: - return nil, helper.ErrInternalf("%w", err) + return nil, structerr.NewInternal("%w", err) } } @@ -71,7 +71,7 @@ func (s *Server) StopTransaction(ctx context.Context, in *gitalypb.StopTransacti case errors.Is(err, transactions.ErrTransactionStopped): return &gitalypb.StopTransactionResponse{}, nil default: - return nil, helper.ErrInternalf("%w", err) + return nil, structerr.NewInternal("%w", err) } } |