vterrors

package
v2.1.0-alpha.1+incompa... Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2016 License: BSD-3-Clause Imports: 8 Imported by: 5

Documentation

Overview

Package vterrors provides helpers for propagating internal errors through the Vitess system (including across RPC boundaries) in a structured way.

Index

Constants

View Source
const (
	PrioritySuccess = iota
	PriorityTransientError
	PriorityQueryNotServed
	PriorityDeadlineExceeded
	PriorityCancelled
	PriorityIntegrityError
	PriorityNotInTx
	PriorityUnknownError
	PriorityInternalError
	PriorityResourceExhausted
	PriorityUnauthenticated
	PriorityPermissionDenied
	PriorityBadInput
)

A list of all vtrpcpb.ErrorCodes, ordered by priority. These priorities are used when aggregating multiple errors in VtGate. Higher priority error codes are more urgent for users to see. They are prioritized based on the following question: assuming a scatter query produced multiple errors, which of the errors is the most likely to give the user useful information about why the query failed and how they should proceed?

View Source
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 AggregateVtGateErrorCodes

func AggregateVtGateErrorCodes(errors []error) vtrpcpb.ErrorCode

AggregateVtGateErrorCodes aggregates a list of errors into a single error code. It does so by finding the highest priority error code in the list.

func AggregateVtGateErrors

func AggregateVtGateErrors(errors []error) error

AggregateVtGateErrors aggregates several errors into a single one.

func ConcatenateErrors

func ConcatenateErrors(errors []error) error

ConcatenateErrors aggregates an array of errors into a single error by string concatenation.

func ErrorCodeToGRPCCode

func ErrorCodeToGRPCCode(code vtrpcpb.ErrorCode) codes.Code

ErrorCodeToGRPCCode maps a vtrpcpb.ErrorCode to a gRPC codes.Code.

func FromError

func FromError(code vtrpcpb.ErrorCode, err error) error

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

func FromGRPCError(err error) error

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

func FromVtRPCError(rpcErr *vtrpcpb.RPCError) error

FromVtRPCError recovers a VitessError from a *vtrpcpb.RPCError (which is how VitessErrors are transmitted across proto3 RPC boundaries).

func GRPCCodeToErrorCode

func GRPCCodeToErrorCode(code codes.Code) vtrpcpb.ErrorCode

GRPCCodeToErrorCode maps a gRPC codes.Code to a vtrpcpb.ErrorCode.

func NewVitessError

func NewVitessError(code vtrpcpb.ErrorCode, err error, format string, args ...interface{}) error

NewVitessError returns a VitessError backed error with the given arguments. Useful for preserving an underlying error while creating a new error message.

func RecoverVtErrorCode

func RecoverVtErrorCode(err error) vtrpcpb.ErrorCode

RecoverVtErrorCode attempts to recover a vtrpcpb.ErrorCode from an error.

func ToGRPCError

func ToGRPCError(err error) error

ToGRPCError returns an error as a gRPC error, with the appropriate error code.

func VtRPCErrorFromVtError

func VtRPCErrorFromVtError(err error) *vtrpcpb.RPCError

VtRPCErrorFromVtError converts from a VtError to a vtrpcpb.RPCError.

func WithPrefix

func WithPrefix(prefix string, in error) error

WithPrefix allows a string to be prefixed to an error. If the original error implements the VtError interface it returns a VitessError wrapping the original error (with one exception: if the original error is an instance of VitessError it doesn't wrap it in a new VitessError instance, but only changes the 'Message' field). Otherwise, it returns a string prefixed with the given prefix.

func WithSuffix

func WithSuffix(in error, suffix string) error

WithSuffix allows a string to be suffixed to an error. If the original error implements the VtError interface it returns a VitessError wrapping the original error (with one exception: if the original error is an instance of VitessError it doesn't wrap it in a new VitessError instance, but only changes the 'Message' field). Otherwise, it returns a string suffixed with the given suffix.

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.

type VtError

type VtError interface {
	VtErrorCode() vtrpcpb.ErrorCode
}

VtError is implemented by any type that exposes a vtrpcpb.ErrorCode.

Jump to

Keyboard shortcuts

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