Documentation ¶
Overview ¶
Package vterrors provides helpers for propagating internal errors through the Vitess system (including across RPC boundaries) in a structured way.
Index ¶
- Constants
- func ConcatenateErrors(errors []error) error
- func ErrorCodeToGRPCCode(code vtrpcpb.ErrorCode) codes.Code
- func FromError(code vtrpcpb.ErrorCode, err error) error
- func FromGRPCError(err error) error
- func FromRPCError(rpcErr *mproto.RPCError) error
- func FromVtRPCError(rpcErr *vtrpcpb.RPCError) error
- func GRPCCodeToErrorCode(code codes.Code) vtrpcpb.ErrorCode
- func NewVitessError(code vtrpcpb.ErrorCode, err error, format string, args ...interface{}) error
- func RPCErrFromVtError(err error) *mproto.RPCError
- func RecoverVtErrorCode(err error) vtrpcpb.ErrorCode
- func ToGRPCError(err error) error
- func VtRPCErrorFromVtError(err error) *vtrpcpb.RPCError
- func WithPrefix(prefix string, in error) error
- func WithSuffix(in error, suffix string) error
- type VitessError
- type VtError
Constants ¶
const GRPCServerErrPrefix = "gRPCServerError:"
GRPCServerErrPrefix is the string we prefix gRPC server errors with. This is necessary because there is currently no good way, in gRPC, to differentiate between an error from a server vs the client. See: https://github.com/grpc/grpc-go/issues/319
Variables ¶
This section is empty.
Functions ¶
func ConcatenateErrors ¶
ConcatenateErrors aggregates an array of errors into a single error by string concatenation
func ErrorCodeToGRPCCode ¶
ErrorCodeToGRPCCode maps a vtrpcpb.ErrorCode to a gRPC codes.Code
func FromError ¶
FromError returns a VitessError with the supplied error code by wrapping an existing error.
func FromGRPCError ¶
FromGRPCError return a grpc error as a VitessError, translating between error codes
func FromRPCError ¶
FromRPCError recovers a VitessError from a *mproto.RPCError (which is how VitessErrors are transmitted across RPC boundaries).
func FromVtRPCError ¶
FromVtRPCError recovers a VitessError from a *vtrpcpb.RPCError (which is how VitessErrors are transmitted across proto3 RPC boundaries).
func GRPCCodeToErrorCode ¶
GRPCCodeToErrorCode maps a gRPC codes.Code to a vtrpcpb.ErrorCode
func NewVitessError ¶
NewVitessError returns a VitessError backed error with the given arguments. Useful for preserving an underlying error while creating a new error message.
func RPCErrFromVtError ¶
RPCErrFromVtError convert from a VtError to an *mproto.RPCError
func RecoverVtErrorCode ¶
RecoverVtErrorCode attempts to recover a vtrpcpb.ErrorCode from an error
func ToGRPCError ¶
ToGRPCError returns an error as a grpc error, with the appropriate error code
func VtRPCErrorFromVtError ¶
VtRPCErrorFromVtError convert from a VtError to a vtrpcpb.RPCError
func WithPrefix ¶
WithPrefix allows a string to be prefixed to an error, without chaining a new VitessError.
func WithSuffix ¶
WithSuffix allows a string to be suffixed to an error, without chaining a new VitessError.
Types ¶
type VitessError ¶
type VitessError struct { // Error code of the Vitess error Code vtrpcpb.ErrorCode // Error message that should be returned. This allows us to change an error message // without losing the underlying error. For example, if you have an error like // context.DeadlikeExceeded, you don't want to modify it - otherwise you would lose // the ability to programatically check for that error. However, you might want to // add some context to the error, giving you a message like "command failed: deadline exceeded". // To do that, you can create a NewVitessError to wrap the original error, but redefine // the error message. Message string // contains filtered or unexported fields }
VitessError is the error type that we use internally for passing structured errors
func (*VitessError) AsString ¶
func (e *VitessError) AsString() string
AsString returns a VitessError as a string, with more detailed information than Error().
func (*VitessError) Error ¶
func (e *VitessError) Error() string
Error implements the error interface. It will return the redefined error message, if there is one. If there isn't, it will return the original error message.
func (*VitessError) VtErrorCode ¶
func (e *VitessError) VtErrorCode() vtrpcpb.ErrorCode
VtErrorCode returns the underlying Vitess error code