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 vtrpc.ErrorCode) codes.Code
- func FromError(code vtrpc.ErrorCode, err error) error
- func FromGRPCError(err error) error
- func FromJSONError(err error) error
- func FromRPCError(rpcErr *mproto.RPCError) error
- func FromVtRPCError(rpcErr *vtrpc.RPCError) error
- func GRPCCodeToErrorCode(code codes.Code) vtrpc.ErrorCode
- func NewVitessError(code vtrpc.ErrorCode, err error, format string, args ...interface{}) error
- func RPCErrFromVtError(err error) *mproto.RPCError
- func RecoverVtErrorCode(err error) vtrpc.ErrorCode
- func ToGRPCError(err error) error
- func ToJSONError(err error) error
- func WithPrefix(prefix string, in error) error
- func WithSuffix(in error, suffix string) error
- type VitessError
- type VtError
Constants ¶
const GRPCServerErrPrefix = "gRPCServerError:"
This is the string that 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 vtrpc.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 FromJSONError ¶
FromJSONError return a JSON-encoded error string as a VitessError.
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 *vtrpc.RPCError (which is how VitessErrors are transmitted across proto3 RPC boundaries).
func GRPCCodeToErrorCode ¶
GRPCCodeToErrorCode maps a gRPC codes.Code to a vtrpc.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 vtrpc.ErrorCode from an error
func ToGRPCError ¶
ToGRPCError returns an error as a grpc error, with the appropriate error code
func ToJSONError ¶
ToJSONError return an error as a JSON-encoded error string. Specifically, it creates a vtrpc.RPCError and marshalls that into JSON.
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 vtrpc.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() vtrpc.ErrorCode
VtErrorCode returns the underlying Vitess error code