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>2023-07-05 16:22:05 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2023-07-06 14:03:20 +0300
commit5bed740931638649d276946967988d992a3b64f3 (patch)
tree7c695089dfd9bd8308f30c6ad57144a6a485880e
parentf9b07d4f6779efb98fca1da6079c43ad7fe12279 (diff)
updateref: Convert `FileDirectoryConflictError` to use error metadata
Convert the `FileDirectoryConflictError` to use error metadata instead of embedding the information into the error message.
-rw-r--r--internal/git/updateref/updateref.go11
-rw-r--r--internal/gitaly/service/operations/branches_test.go6
2 files changed, 15 insertions, 2 deletions
diff --git a/internal/git/updateref/updateref.go b/internal/git/updateref/updateref.go
index 54e18c76a..de0be8ec5 100644
--- a/internal/git/updateref/updateref.go
+++ b/internal/git/updateref/updateref.go
@@ -60,7 +60,16 @@ type FileDirectoryConflictError struct {
}
func (e FileDirectoryConflictError) Error() string {
- return fmt.Sprintf("%q conflicts with %q", e.ConflictingReferenceName, e.ExistingReferenceName)
+ return "file directory conflict"
+}
+
+// ErrorMetadata implements the `structerr.ErrorMetadater` interface and provides the name of preexisting and
+// conflicting reference names.
+func (e FileDirectoryConflictError) ErrorMetadata() []structerr.MetadataItem {
+ return []structerr.MetadataItem{
+ {Key: "conflicting_reference", Value: e.ConflictingReferenceName},
+ {Key: "existing_reference", Value: e.ExistingReferenceName},
+ }
}
// InTransactionConflictError is returned when attempting to modify two references in the same transaction
diff --git a/internal/gitaly/service/operations/branches_test.go b/internal/gitaly/service/operations/branches_test.go
index dfbd3bbde..f89b58073 100644
--- a/internal/gitaly/service/operations/branches_test.go
+++ b/internal/gitaly/service/operations/branches_test.go
@@ -401,7 +401,11 @@ func TestUserCreateBranch_Failure(t *testing.T) {
branchName: "improve",
startPoint: "master",
user: gittest.TestUser,
- err: status.Errorf(codes.FailedPrecondition, "Could not update refs/heads/improve. Please refresh and try again."),
+ err: testhelper.WithInterceptedMetadataItems(
+ structerr.NewFailedPrecondition("Could not update refs/heads/improve. Please refresh and try again."),
+ structerr.MetadataItem{Key: "conflicting_reference", Value: "refs/heads/improve"},
+ structerr.MetadataItem{Key: "existing_reference", Value: "refs/heads/improve/awesome"},
+ ),
},
}