diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-20 16:57:49 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-22 14:38:39 +0300 |
commit | 063f11e725f64cfc5d09f5504c5240f06fedeabd (patch) | |
tree | f39200e236372a89e9799c19a4b30a41e37f1090 | |
parent | 942d8298610eded70b5204863048617ee1c136cd (diff) |
helper: Add function to format `Canceled` errors
Add a function to format gRPC errors with an error code of `Canceled`.
-rw-r--r-- | internal/helper/error.go | 6 | ||||
-rw-r--r-- | internal/helper/error_test.go | 5 |
2 files changed, 11 insertions, 0 deletions
diff --git a/internal/helper/error.go b/internal/helper/error.go index e649e5231..517fb1d70 100644 --- a/internal/helper/error.go +++ b/internal/helper/error.go @@ -60,6 +60,12 @@ func wrapError(code codes.Code, err error) error { return err } +// ErrCanceledf wraps a formatted error with codes.Canceled, unless the formatted error is a +// wrapped gRPC error. +func ErrCanceledf(format string, a ...interface{}) error { + return formatError(codes.Canceled, format, a...) +} + // ErrInternalf wraps a formatted error with codes.Internal, unless the formatted error is a // wrapped gRPC error. func ErrInternalf(format string, a ...interface{}) error { diff --git a/internal/helper/error_test.go b/internal/helper/error_test.go index 047aa6853..3de56385d 100644 --- a/internal/helper/error_test.go +++ b/internal/helper/error_test.go @@ -99,6 +99,11 @@ func TestErrorf(t *testing.T) { expectedCode codes.Code }{ { + desc: "Canceledf", + errorf: ErrCanceledf, + expectedCode: codes.Canceled, + }, + { desc: "Internalf", errorf: ErrInternalf, expectedCode: codes.Internal, |