diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-12-20 15:45:50 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-12-20 15:50:00 +0300 |
commit | 85c9c0efa10f31f2e14800b8feec1a877c0c0235 (patch) | |
tree | 65cbcd67c73d0a0314de0cf31236523813d292f7 | |
parent | 2bc64b5e1f449aadb2de37d2b70ebdf5c954c799 (diff) |
commit: Don't put tree entry name into error message
When checking our production logs for gitlab.com, the top-most error
message we see is that a specific tree entry was not found in the
`TreeEntry()` RPC. This error includes the path of the tree entry that
wasn't found, which makes it impossible to deduplicate this error in
Sentry.
Convert the error to use structured metadata instead to fix this. This
also serves as a test balloon to verify that we indeed propagate the
gRPC error metadata as expected in production systems.
Changelog: fixed
-rw-r--r-- | internal/gitaly/service/commit/tree_entry.go | 2 | ||||
-rw-r--r-- | internal/gitaly/service/commit/tree_entry_test.go | 6 |
2 files changed, 4 insertions, 4 deletions
diff --git a/internal/gitaly/service/commit/tree_entry.go b/internal/gitaly/service/commit/tree_entry.go index ae6c34f3f..3d43d0ddb 100644 --- a/internal/gitaly/service/commit/tree_entry.go +++ b/internal/gitaly/service/commit/tree_entry.go @@ -28,7 +28,7 @@ func sendTreeEntry( } if treeEntry == nil || len(treeEntry.Oid) == 0 { - return structerr.NewNotFound("not found: %s", path) + return structerr.NewNotFound("tree entry not found").WithMetadata("path", path) } if treeEntry.Type == gitalypb.TreeEntry_COMMIT { diff --git a/internal/gitaly/service/commit/tree_entry_test.go b/internal/gitaly/service/commit/tree_entry_test.go index 30a74f90b..781f1cd1b 100644 --- a/internal/gitaly/service/commit/tree_entry_test.go +++ b/internal/gitaly/service/commit/tree_entry_test.go @@ -214,17 +214,17 @@ func TestFailedTreeEntry(t *testing.T) { { name: "Path is outside of repository", req: &gitalypb.TreeEntryRequest{Repository: repo, Revision: []byte("913c66a37b4a45b9769037c55c2d238bd0942d2e"), Path: []byte("../bar/.gitkeep")}, // Git blows up on paths like this - expectedErr: structerr.NewNotFound("not found: ../bar/.gitkeep"), + expectedErr: structerr.NewNotFound("tree entry not found"), }, { name: "Missing file with space in path", req: &gitalypb.TreeEntryRequest{Repository: repo, Revision: []byte("deadfacedeadfacedeadfacedeadfacedeadface"), Path: []byte("with space/README.md")}, - expectedErr: structerr.NewNotFound("not found: with space/README.md"), + expectedErr: structerr.NewNotFound("tree entry not found"), }, { name: "Missing file", req: &gitalypb.TreeEntryRequest{Repository: repo, Revision: []byte("e63f41fe459e62e1228fcef60d7189127aeba95a"), Path: []byte("missing.rb")}, - expectedErr: structerr.NewNotFound("not found: missing.rb"), + expectedErr: structerr.NewNotFound("tree entry not found"), }, } { t.Run(tc.name, func(t *testing.T) { |