vterrors

package
v2.0.0-alpha5+incompat... Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2015 License: BSD-3-Clause Imports: 8 Imported by: 0

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 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

func ConcatenateErrors(errors []error) error

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

func ErrorCodeToGRPCCode

func ErrorCodeToGRPCCode(code vtrpc.ErrorCode) codes.Code

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

func FromError

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

FromError returns a VitessError with the supplied error code by wrapping an existing error.

func FromGRPCError

func FromGRPCError(err error) error

FromGRPCError return a grpc error as a VitessError, translating between error codes

func FromJSONError

func FromJSONError(err error) error

FromJSONError return a JSON-encoded error string as a VitessError.

func FromRPCError

func FromRPCError(rpcErr *mproto.RPCError) error

FromRPCError recovers a VitessError from a *mproto.RPCError (which is how VitessErrors are transmitted across RPC boundaries).

func FromVtRPCError

func FromVtRPCError(rpcErr *vtrpc.RPCError) error

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

func GRPCCodeToErrorCode

func GRPCCodeToErrorCode(code codes.Code) vtrpc.ErrorCode

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

func NewVitessError

func NewVitessError(code vtrpc.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 RPCErrFromVtError

func RPCErrFromVtError(err error) *mproto.RPCError

RPCErrFromVtError convert from a VtError to an *mproto.RPCError

func RecoverVtErrorCode

func RecoverVtErrorCode(err error) vtrpc.ErrorCode

RecoverVtErrorCode attempts to recover a vtrpc.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 ToJSONError

func ToJSONError(err error) error

ToJSONError return an error as a JSON-encoded error string. Specifically, it creates a vtrpc.RPCError and marshalls that into JSON.

func WithPrefix

func WithPrefix(prefix string, in error) error

WithPrefix allows a string to be prefixed to an error, without chaining a new VitessError.

func WithSuffix

func WithSuffix(in error, suffix string) error

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

type VtError

type VtError interface {
	VtErrorCode() vtrpc.ErrorCode
}

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

Jump to

Keyboard shortcuts

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