diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2022-11-14 12:58:22 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2022-11-15 15:07:12 +0300 |
commit | 064567f4a4a0314cf52a89ae8df0b4e13e7d54d6 (patch) | |
tree | fefc824eb97b7f0a1cf6ca9d08a6cc1cb3a3d1dc | |
parent | bc0881d0c2d26ea3b5d299e7dcfde04440b2e43e (diff) |
blob: Return InvalidArgument error code for invalid input
An invalid request should return an InvalidArgument code to
the caller. Seems like it was broken on one of the
last refactoring or was not done correctly initially. In any
case now it returns a proper code.
This change also simplifies error creation using helpers.
-rw-r--r-- | internal/gitaly/service/blob/lfs_pointers.go | 6 | ||||
-rw-r--r-- | internal/gitaly/service/blob/lfs_pointers_test.go | 13 |
2 files changed, 16 insertions, 3 deletions
diff --git a/internal/gitaly/service/blob/lfs_pointers.go b/internal/gitaly/service/blob/lfs_pointers.go index ce51cd01a..ded6e598b 100644 --- a/internal/gitaly/service/blob/lfs_pointers.go +++ b/internal/gitaly/service/blob/lfs_pointers.go @@ -82,7 +82,7 @@ func (s *server) ListAllLFSPointers(in *gitalypb.ListAllLFSPointersRequest, stre repository := in.GetRepository() if err := service.ValidateRepository(repository); err != nil { - return err + return helper.ErrInvalidArgument(err) } repo := s.localrepo(repository) @@ -222,7 +222,7 @@ func sendLFSPointers(chunker *chunk.Chunker, iter gitpipe.CatfileObjectIterator, // is 200 bytes in size. So it's not much of a problem to read this into memory // completely. if _, err := io.Copy(buffer, lfsPointer); err != nil { - return helper.ErrInternal(fmt.Errorf("reading LFS pointer data: %w", err)) + return helper.ErrInternalf("reading LFS pointer data: %w", err) } if !git.IsLFSPointer(buffer.Bytes()) { @@ -237,7 +237,7 @@ func sendLFSPointers(chunker *chunk.Chunker, iter gitpipe.CatfileObjectIterator, Size: int64(len(objectData)), Oid: lfsPointer.ObjectID().String(), }); err != nil { - return helper.ErrInternal(fmt.Errorf("sending LFS pointer chunk: %w", err)) + return helper.ErrInternalf("sending LFS pointer chunk: %w", err) } i++ diff --git a/internal/gitaly/service/blob/lfs_pointers_test.go b/internal/gitaly/service/blob/lfs_pointers_test.go index 4e2c1bd38..3455260a0 100644 --- a/internal/gitaly/service/blob/lfs_pointers_test.go +++ b/internal/gitaly/service/blob/lfs_pointers_test.go @@ -290,6 +290,19 @@ size 12345` }, }, receivePointers(t, stream)) }) + + t.Run("no repository provided", func(t *testing.T) { + _, _, _, client := setup(t, ctx) + stram, err := client.ListAllLFSPointers(ctx, &gitalypb.ListAllLFSPointersRequest{ + Repository: nil, + }) + require.NoError(t, err) + _, err = stram.Recv() + testhelper.RequireGrpcError(t, status.Error(codes.InvalidArgument, testhelper.GitalyOrPraefectMessage( + "empty Repository", + "repo scoped: empty Repository", + )), err) + }) } func TestSuccessfulGetLFSPointersRequest(t *testing.T) { |