errgrpc

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2024 License: Apache-2.0 Imports: 16 Imported by: 33

Documentation

Overview

Package errgrpc provides utility functions for translating errors to and from a gRPC context.

The functions ToGRPC and ToNative can be used to map server-side and client-side errors to the correct types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToGRPC

func ToGRPC(err error) error

ToGRPC will attempt to map the error into a grpc error, from the error types defined in the the errdefs package and attempign to preserve the original description. Any type which does not resolve to a defined error type will be assigned the unknown error code.

Further information may be extracted from certain errors depending on their type. The grpc error details will be used to attempt to preserve as much of the error structures and types as possible.

Errors which can be marshaled using protobuf or typeurl will be considered for including as GRPC error details. Additionally, use the following interfaces in errors to preserve custom types:

WrapError(error) error     - Used to wrap the previous error
JoinErrors(...error) error - Used to join all previous errors
CollapseError()            - Used for errors which carry information but
                             should not have their error message shown.

func ToGRPCf

func ToGRPCf(err error, format string, args ...interface{}) error

ToGRPCf maps the error to grpc error codes, assembling the formatting string and combining it with the target error string.

This is equivalent to grpc.ToGRPC(fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), err))

func ToNative

func ToNative(err error) error

ToNative returns the underlying error from a grpc service based on the grpc error code. The grpc details are used to add wrap the error in more context or support multiple errors.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL