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 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 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. Use this method also when you want to create a VitessError without a custom message. For example:
err := vterrors.FromError(vtrpcpb.ErrorCode_INTERNAL_ERROR, errors.New("no valid endpoint"))
func FromGRPCError ¶
FromGRPCError returns a gRPC error as a VitessError, translating between error codes. However, there are a few errors which are not translated and passed as they are. For example, io.EOF since our code base checks for this error to find out that a stream has finished.
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 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 converts 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.