package errgrpc
import "github.com/containerd/errdefs/errgrpc"
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 ¶
- func ToGRPC(err error) error
- func ToGRPCf(err error, format string, args ...interface{}) error
- func ToNative(err error) error
Functions ¶
func ToGRPC ¶
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 ¶
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 ¶
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.
Source Files ¶
- Version
- v0.2.0
- Published
- Sep 2, 2024
- Platform
- windows/amd64
- Imports
- 16 packages
- Last checked
- 1 hour ago –
Tools for package owners.