cgerrors

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: Apache-2.0 Imports: 11 Imported by: 13

Documentation

Overview

Package cgerrors provides a way to return detailed information for an RPC request error. The error is normally JSON encoded.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorCode_name = map[int32]string{
		0:  "OK",
		1:  "Canceled",
		2:  "Unknown",
		3:  "InvalidArgument",
		4:  "DeadlineExceeded",
		5:  "NotFound",
		6:  "AlreadyExists",
		7:  "PermissionDenied",
		8:  "ResourceExhausted",
		9:  "FailedPrecondition",
		10: "Aborted",
		11: "OutOfRange",
		12: "Unimplemented",
		13: "Internal",
		14: "Unavailable",
		15: "DataLoss",
		16: "Unauthenticated",
	}
	ErrorCode_value = map[string]int32{
		"OK":                 0,
		"Canceled":           1,
		"Unknown":            2,
		"InvalidArgument":    3,
		"DeadlineExceeded":   4,
		"NotFound":           5,
		"AlreadyExists":      6,
		"PermissionDenied":   7,
		"ResourceExhausted":  8,
		"FailedPrecondition": 9,
		"Aborted":            10,
		"OutOfRange":         11,
		"Unimplemented":      12,
		"Internal":           13,
		"Unavailable":        14,
		"DataLoss":           15,
		"Unauthenticated":    16,
	}
)

Enum value maps for ErrorCode.

View Source
var File_errors_proto protoreflect.FileDescriptor

Functions

func Equal

func Equal(err1 error, err2 error) bool

Equal tries to compare errors

func Is

func Is(err, target error) bool

Is compares the errors with their values.

func IsAlreadyExists

func IsAlreadyExists(err error) bool

IsAlreadyExists checks if given error means that given entity already exists.

func IsDeadlineExceeded

func IsDeadlineExceeded(err error) bool

IsDeadlineExceeded checks if given error is of type Deadline Exceeded.

func IsInternal

func IsInternal(err error) bool

IsInternal checks if the input is an internal error.

func IsInvalidArgument

func IsInvalidArgument(err error) bool

IsInvalidArgument checks if given error means that given entity already exists.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound checks if given input error is of code NotFound.

func IsPermissionDenied

func IsPermissionDenied(err error) bool

IsPermissionDenied checks if given error is of type PermissionDenied.

func IsUnauthenticated

func IsUnauthenticated(err error) bool

IsUnauthenticated checks if given error is an unauthenticated error.

func IsUnimplemented added in v0.0.5

func IsUnimplemented(err error) bool

IsUnimplemented checks if given error contains Unimplemented code.

func ToGRPCError

func ToGRPCError(err error) error

ToGRPCError converts an error to GRPC status.Status.

Types

type Error

type Error struct {
	Id      string            `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	Code    ErrorCode         `protobuf:"varint,2,opt,name=code,proto3,enum=cgerrors.ErrorCode" json:"code,omitempty"`
	Detail  string            `protobuf:"bytes,3,opt,name=detail,proto3" json:"detail,omitempty"`
	Process string            `protobuf:"bytes,4,opt,name=process,proto3" json:"process,omitempty"`
	Meta    map[string]string `` /* 149-byte string literal not displayed */
	// contains filtered or unexported fields
}

Error is the error message that has id, it's code and a detail.

func ErrAlreadyExists

func ErrAlreadyExists(a ...interface{}) *Error

ErrAlreadyExists generates a 409 error.

func ErrAlreadyExistsf

func ErrAlreadyExistsf(format string, a ...interface{}) *Error

ErrAlreadyExistsf generates formatted 409 error.

func ErrDeadlineExceeded

func ErrDeadlineExceeded(a ...interface{}) *Error

ErrDeadlineExceeded generates a 408 error.

func ErrDeadlineExceededf

func ErrDeadlineExceededf(format string, a ...interface{}) *Error

ErrDeadlineExceededf generates formatted 408 error.

func ErrInternal

func ErrInternal(a ...interface{}) *Error

ErrInternal generates a 500 error.

func ErrInternalf

func ErrInternalf(format string, a ...interface{}) *Error

ErrInternalf generates formatted 500 error.

func ErrInvalidArgument

func ErrInvalidArgument(a ...interface{}) *Error

ErrInvalidArgument generates a 400 error.

func ErrInvalidArgumentf

func ErrInvalidArgumentf(format string, a ...interface{}) *Error

ErrInvalidArgumentf generates formatted 400 error.

func ErrNotFound

func ErrNotFound(a ...interface{}) *Error

ErrNotFound generates a 404 error.

func ErrNotFoundf

func ErrNotFoundf(format string, a ...interface{}) *Error

ErrNotFoundf generates formatted 404 error.

func ErrPermissionDenied

func ErrPermissionDenied(a ...interface{}) *Error

ErrPermissionDenied generates a 403 error.

func ErrPermissionDeniedf

func ErrPermissionDeniedf(format string, a ...interface{}) *Error

ErrPermissionDeniedf generates a 403 error.

func ErrUnauthenticated

func ErrUnauthenticated(a ...interface{}) *Error

ErrUnauthenticated generates a 401 error.

func ErrUnauthenticatedf

func ErrUnauthenticatedf(format string, a ...interface{}) *Error

ErrUnauthenticatedf generates 401 error with formatted message.

func ErrUnimplemented added in v0.0.5

func ErrUnimplemented(a ...interface{}) *Error

ErrUnimplemented generates Unimplemented error.

func ErrUnimplementedf added in v0.0.5

func ErrUnimplementedf(format string, a ...interface{}) *Error

ErrUnimplementedf generates Unimplemented error with formatting.

func FromError

func FromError(err error) *Error

FromError try to convert go error to *Error

func New

func New(id, detail string, code ErrorCode) *Error

New generates a custom error.

func Parse

func Parse(err string) *Error

Parse tries to parse a JSON string into an error. If that fails, it will set the given string as the error detail.

func To

func To(err error) *Error

To type check if given error is of *Error type or has encoded ErrorCode in it. Otherwise creates a new error with Unknown code.

func (*Error) Descriptor deprecated

func (*Error) Descriptor() ([]byte, []int)

Deprecated: Use Error.ProtoReflect.Descriptor instead.

func (*Error) Error

func (x *Error) Error() string

Error implements error interface.

func (*Error) GRPCStatus

func (x *Error) GRPCStatus() *status.Status

GRPCStatus implements grpc client interface used to convert statuses.

func (*Error) GetCode

func (x *Error) GetCode() ErrorCode

func (*Error) GetDetail

func (x *Error) GetDetail() string

func (*Error) GetId

func (x *Error) GetId() string

func (*Error) GetMeta

func (x *Error) GetMeta() map[string]string

func (*Error) GetProcess

func (x *Error) GetProcess() string

func (*Error) Is

func (x *Error) Is(err error) bool

Is implements errors interface used by the

func (*Error) ProtoMessage

func (*Error) ProtoMessage()

func (*Error) ProtoReflect

func (x *Error) ProtoReflect() protoreflect.Message

func (*Error) Reset

func (x *Error) Reset()

func (*Error) String

func (x *Error) String() string

func (*Error) WithCode

func (x *Error) WithCode(code ErrorCode) *Error

WithCode sets the code for given error.

func (*Error) WithMeta

func (x *Error) WithMeta(key, value string) *Error

WithMeta sets the key, value metadata for given error.

func (*Error) WithProcess

func (x *Error) WithProcess(process string) *Error

WithProcess sets the process for given error.

type ErrorCode

type ErrorCode int32

ErrorCode is a code that defines errors specification.

const (
	ErrorCode_OK                 ErrorCode = 0
	ErrorCode_Canceled           ErrorCode = 1
	ErrorCode_Unknown            ErrorCode = 2
	ErrorCode_InvalidArgument    ErrorCode = 3
	ErrorCode_DeadlineExceeded   ErrorCode = 4
	ErrorCode_NotFound           ErrorCode = 5
	ErrorCode_AlreadyExists      ErrorCode = 6
	ErrorCode_PermissionDenied   ErrorCode = 7
	ErrorCode_ResourceExhausted  ErrorCode = 8
	ErrorCode_FailedPrecondition ErrorCode = 9
	ErrorCode_Aborted            ErrorCode = 10
	ErrorCode_OutOfRange         ErrorCode = 11
	ErrorCode_Unimplemented      ErrorCode = 12
	ErrorCode_Internal           ErrorCode = 13
	ErrorCode_Unavailable        ErrorCode = 14
	ErrorCode_DataLoss           ErrorCode = 15
	ErrorCode_Unauthenticated    ErrorCode = 16
)

func Code

func Code(err error) ErrorCode

Code gets the code defined in given

func (ErrorCode) Descriptor

func (ErrorCode) Descriptor() protoreflect.EnumDescriptor

func (ErrorCode) Enum

func (x ErrorCode) Enum() *ErrorCode

func (ErrorCode) EnumDescriptor deprecated

func (ErrorCode) EnumDescriptor() ([]byte, []int)

Deprecated: Use ErrorCode.Descriptor instead.

func (ErrorCode) Number

func (x ErrorCode) Number() protoreflect.EnumNumber

func (ErrorCode) String

func (x ErrorCode) String() string

func (ErrorCode) ToGRPCCode

func (x ErrorCode) ToGRPCCode() codes.Code

ToGRPCCode gets the related grpc code.

func (ErrorCode) Type

type ErrorCoder

type ErrorCoder interface {
	ErrorCode(err error) ErrorCode
}

ErrorCoder is an interface used to obtain an error code from given error within given implementation.

type GRPCError

type GRPCError interface {
	GRPCStatus() *status.Status
}

GRPCError is an interface used to get grpcStatus

Jump to

Keyboard shortcuts

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