diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-07-26 14:59:53 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-07-28 13:38:42 +0300 |
commit | 3ec4fbdb76b12db4d81b1e2e6b6f39e335a27a8c (patch) | |
tree | 5874323052b0d3f8f90d9149ce8284feb9d506c0 /internal/helper | |
parent | 70528ccc30acd59c77c16b4b45a21d254f0bdba0 (diff) |
helper: Make `DecorateError()` private
There are no external callsites of `DecorateError()` anymore given that
they've all been converted to use our higher-level error functions.
Make the function private and rename it to `wrapError()` to not grow new
users of it again.
Diffstat (limited to 'internal/helper')
-rw-r--r-- | internal/helper/error.go | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/internal/helper/error.go b/internal/helper/error.go index fe319e8e2..d4b7b44b8 100644 --- a/internal/helper/error.go +++ b/internal/helper/error.go @@ -21,33 +21,33 @@ func (sw statusWrapper) Unwrap() error { return sw.error } -// DecorateError unless it's already a grpc error. -// If given nil it will return nil. -func DecorateError(code codes.Code, err error) error { - if GrpcCode(err) == codes.Unknown { - return statusWrapper{err, status.New(code, err.Error())} - } - return err -} - // ErrCanceled wraps err with codes.Canceled, unless err is already a gRPC error. -func ErrCanceled(err error) error { return DecorateError(codes.Canceled, err) } +func ErrCanceled(err error) error { return wrapError(codes.Canceled, err) } // ErrInternal wraps err with codes.Internal, unless err is already a gRPC error. -func ErrInternal(err error) error { return DecorateError(codes.Internal, err) } +func ErrInternal(err error) error { return wrapError(codes.Internal, err) } // ErrInvalidArgument wraps err with codes.InvalidArgument, unless err is already a gRPC error. -func ErrInvalidArgument(err error) error { return DecorateError(codes.InvalidArgument, err) } +func ErrInvalidArgument(err error) error { return wrapError(codes.InvalidArgument, err) } // ErrNotFound wraps error with codes.NotFound, unless err is already a gRPC error. -func ErrNotFound(err error) error { return DecorateError(codes.NotFound, err) } +func ErrNotFound(err error) error { return wrapError(codes.NotFound, err) } // ErrPreconditionFailed wraps err with codes.FailedPrecondition, unless err is already a gRPC // error. -func ErrPreconditionFailed(err error) error { return DecorateError(codes.FailedPrecondition, err) } +func ErrPreconditionFailed(err error) error { return wrapError(codes.FailedPrecondition, err) } // ErrUnavailable wraps err with codes.Unavailable, unless err is already a gRPC error. -func ErrUnavailable(err error) error { return DecorateError(codes.Unavailable, err) } +func ErrUnavailable(err error) error { return wrapError(codes.Unavailable, 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 { + if GrpcCode(err) == codes.Unknown { + return statusWrapper{err, status.New(code, err.Error())} + } + return err +} // ErrInternalf wraps a formatted error with codes.Internal, unless the formatted error is a // wrapped gRPC error. |