diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-07-26 14:10:20 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-07-28 13:36:13 +0300 |
commit | bec0ee646c2121013fee49510f27d3db439afe99 (patch) | |
tree | fad3ab12c3cf792f6c83a1832a55a7f1a34c640c /internal/helper | |
parent | 2b0dedfc85c469d4e4a7f767ae0c09da346cb4b7 (diff) |
helper: Group error functions by formatting/non-formatting
We've got two kinds of helper functions to format errors with gRPC codes:
those which do formatting, and those which don't. Given that their
implementation is the same across each of these sets (except for the
error code), it makes more sense to group them by their formatting
nature instead of by their error code.
Reorder them for improved readability.
Diffstat (limited to 'internal/helper')
-rw-r--r-- | internal/helper/error.go | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/internal/helper/error.go b/internal/helper/error.go index 91879a308..3f895cd4c 100644 --- a/internal/helper/error.go +++ b/internal/helper/error.go @@ -32,30 +32,30 @@ func DecorateError(code codes.Code, err error) error { // ErrInternal wraps err with codes.Internal, unless err is already a grpc error func ErrInternal(err error) error { return DecorateError(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) } + +// ErrPreconditionFailed wraps err with codes.FailedPrecondition, unless err is already a grpc error +func ErrPreconditionFailed(err error) error { return DecorateError(codes.FailedPrecondition, err) } + +// ErrNotFound wraps error with codes.NotFound, unless err is already a grpc error +func ErrNotFound(err error) error { return DecorateError(codes.NotFound, err) } + // ErrInternalf wrapps a formatted error with codes.Internal, clobbering any existing grpc error func ErrInternalf(format string, a ...interface{}) error { return ErrInternal(fmt.Errorf(format, a...)) } -// ErrInvalidArgument wraps err with codes.InvalidArgument, unless err is already a grpc error -func ErrInvalidArgument(err error) error { return DecorateError(codes.InvalidArgument, err) } - // ErrInvalidArgumentf wraps a formatted error with codes.InvalidArgument, clobbering any existing grpc error func ErrInvalidArgumentf(format string, a ...interface{}) error { return ErrInvalidArgument(fmt.Errorf(format, a...)) } -// ErrPreconditionFailed wraps err with codes.FailedPrecondition, unless err is already a grpc error -func ErrPreconditionFailed(err error) error { return DecorateError(codes.FailedPrecondition, err) } - // ErrPreconditionFailedf wraps a formatted error with codes.FailedPrecondition, clobbering any existing grpc error func ErrPreconditionFailedf(format string, a ...interface{}) error { return ErrPreconditionFailed(fmt.Errorf(format, a...)) } -// ErrNotFound wraps error with codes.NotFound, unless err is already a grpc error -func ErrNotFound(err error) error { return DecorateError(codes.NotFound, err) } - // GrpcCode emulates the old grpc.Code function: it translates errors into codes.Code values. func GrpcCode(err error) codes.Code { if err == nil { |