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:
authorSami Hiltunen <shiltunen@gitlab.com>2021-07-27 16:00:35 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2021-08-31 15:57:47 +0300
commitec619962966cc59d889c7792b1613b3ac4c0968f (patch)
tree21f0bf5f53752f4e5a6e916666ad9aef9b6696ae
parentb790880102f46230eec34519b8abbfd13cdaaab5 (diff)
helper: add already exists error decorator
This commit adds a helper method for wrapping an error with AlreadyExists status code if the error isn't already a status.
-rw-r--r--internal/helper/error.go3
-rw-r--r--internal/helper/error_test.go5
2 files changed, 8 insertions, 0 deletions
diff --git a/internal/helper/error.go b/internal/helper/error.go
index 10551c013..6075866ae 100644
--- a/internal/helper/error.go
+++ b/internal/helper/error.go
@@ -45,6 +45,9 @@ func ErrUnavailable(err error) error { return wrapError(codes.Unavailable, err)
// ErrPermissionDenied wraps err with codes.PermissionDenied, unless err is already a gRPC error.
func ErrPermissionDenied(err error) error { return wrapError(codes.PermissionDenied, err) }
+// ErrAlreadyExists wraps err with codes.AlreadyExists, unless err is already a gRPC error.
+func ErrAlreadyExists(err error) error { return wrapError(codes.AlreadyExists, err) }
+
// wrapError wraps the given error with the error code unless it's already a gRPC error. If given
// nil it will return nil.
func wrapError(code codes.Code, err error) error {
diff --git a/internal/helper/error_test.go b/internal/helper/error_test.go
index 65f7bab91..ad07e90d2 100644
--- a/internal/helper/error_test.go
+++ b/internal/helper/error_test.go
@@ -55,6 +55,11 @@ func TestError(t *testing.T) {
errorf: ErrUnavailable,
code: codes.Unavailable,
},
+ {
+ desc: "AlreadyExists",
+ errorf: ErrAlreadyExists,
+ code: codes.AlreadyExists,
+ },
} {
t.Run(tc.desc, func(t *testing.T) {
// tc.code and our canary test code must not