Documentation
¶
Overview ¶
Package cgerrors provides a way to return detailed information for an RPC request error. The error is normally JSON encoded.
Index ¶
- Variables
- func Equal(err1 error, err2 error) bool
- func Is(err, target error) bool
- func IsAlreadyExists(err error) bool
- func IsDeadlineExceeded(err error) bool
- func IsInternal(err error) bool
- func IsInvalidArgument(err error) bool
- func IsNotFound(err error) bool
- func IsPermissionDenied(err error) bool
- func IsUnauthenticated(err error) bool
- func IsUnimplemented(err error) bool
- func ToGRPCError(err error) error
- type Error
- func ErrAlreadyExists(a ...interface{}) *Error
- func ErrAlreadyExistsf(format string, a ...interface{}) *Error
- func ErrDeadlineExceeded(a ...interface{}) *Error
- func ErrDeadlineExceededf(format string, a ...interface{}) *Error
- func ErrInternal(a ...interface{}) *Error
- func ErrInternalf(format string, a ...interface{}) *Error
- func ErrInvalidArgument(a ...interface{}) *Error
- func ErrInvalidArgumentf(format string, a ...interface{}) *Error
- func ErrNotFound(a ...interface{}) *Error
- func ErrNotFoundf(format string, a ...interface{}) *Error
- func ErrPermissionDenied(a ...interface{}) *Error
- func ErrPermissionDeniedf(format string, a ...interface{}) *Error
- func ErrUnauthenticated(a ...interface{}) *Error
- func ErrUnauthenticatedf(format string, a ...interface{}) *Error
- func ErrUnimplemented(a ...interface{}) *Error
- func ErrUnimplementedf(format string, a ...interface{}) *Error
- func FromError(err error) *Error
- func New(id, detail string, code ErrorCode) *Error
- func Parse(err string) *Error
- func To(err error) *Error
- func (*Error) Descriptor() ([]byte, []int)deprecated
- func (x *Error) Error() string
- func (x *Error) GRPCStatus() *status.Status
- func (x *Error) GetCode() ErrorCode
- func (x *Error) GetDetail() string
- func (x *Error) GetId() string
- func (x *Error) GetMeta() map[string]string
- func (x *Error) GetProcess() string
- func (x *Error) Is(err error) bool
- func (*Error) ProtoMessage()
- func (x *Error) ProtoReflect() protoreflect.Message
- func (x *Error) Reset()
- func (x *Error) String() string
- func (x *Error) WithCode(code ErrorCode) *Error
- func (x *Error) WithMeta(key, value string) *Error
- func (x *Error) WithProcess(process string) *Error
- type ErrorCode
- func (ErrorCode) Descriptor() protoreflect.EnumDescriptor
- func (x ErrorCode) Enum() *ErrorCode
- func (ErrorCode) EnumDescriptor() ([]byte, []int)deprecated
- func (x ErrorCode) Number() protoreflect.EnumNumber
- func (x ErrorCode) String() string
- func (x ErrorCode) ToGRPCCode() codes.Code
- func (ErrorCode) Type() protoreflect.EnumType
- type ErrorCoder
- type GRPCError
Constants ¶
This section is empty.
Variables ¶
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.
var File_errors_proto protoreflect.FileDescriptor
Functions ¶
func IsAlreadyExists ¶
IsAlreadyExists checks if given error means that given entity already exists.
func IsDeadlineExceeded ¶
IsDeadlineExceeded checks if given error is of type Deadline Exceeded.
func IsInternal ¶
IsInternal checks if the input is an internal error.
func IsInvalidArgument ¶
IsInvalidArgument checks if given error means that given entity already exists.
func IsNotFound ¶
IsNotFound checks if given input error is of code NotFound.
func IsPermissionDenied ¶
IsPermissionDenied checks if given error is of type PermissionDenied.
func IsUnauthenticated ¶
IsUnauthenticated checks if given error is an unauthenticated error.
func IsUnimplemented ¶ added in v0.0.5
IsUnimplemented checks if given error contains Unimplemented code.
func ToGRPCError ¶
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 ¶
ErrAlreadyExistsf generates formatted 409 error.
func ErrDeadlineExceeded ¶
func ErrDeadlineExceeded(a ...interface{}) *Error
ErrDeadlineExceeded generates a 408 error.
func ErrDeadlineExceededf ¶
ErrDeadlineExceededf generates formatted 408 error.
func ErrInternalf ¶
ErrInternalf generates formatted 500 error.
func ErrInvalidArgument ¶
func ErrInvalidArgument(a ...interface{}) *Error
ErrInvalidArgument generates a 400 error.
func ErrInvalidArgumentf ¶
ErrInvalidArgumentf generates formatted 400 error.
func ErrNotFoundf ¶
ErrNotFoundf generates formatted 404 error.
func ErrPermissionDenied ¶
func ErrPermissionDenied(a ...interface{}) *Error
ErrPermissionDenied generates a 403 error.
func ErrPermissionDeniedf ¶
ErrPermissionDeniedf generates a 403 error.
func ErrUnauthenticated ¶
func ErrUnauthenticated(a ...interface{}) *Error
ErrUnauthenticated generates a 401 error.
func ErrUnauthenticatedf ¶
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
ErrUnimplementedf generates Unimplemented error with formatting.
func Parse ¶
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 ¶
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) GRPCStatus ¶
GRPCStatus implements grpc client interface used to convert statuses.
func (*Error) GetProcess ¶
func (*Error) ProtoMessage ¶
func (*Error) ProtoMessage()
func (*Error) ProtoReflect ¶
func (x *Error) ProtoReflect() protoreflect.Message
func (*Error) WithProcess ¶
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_DataLoss ErrorCode = 15 ErrorCode_Unauthenticated ErrorCode = 16 )
func (ErrorCode) Descriptor ¶
func (ErrorCode) Descriptor() protoreflect.EnumDescriptor
func (ErrorCode) EnumDescriptor
deprecated
func (ErrorCode) Number ¶
func (x ErrorCode) Number() protoreflect.EnumNumber
func (ErrorCode) ToGRPCCode ¶
ToGRPCCode gets the related grpc code.
func (ErrorCode) Type ¶
func (ErrorCode) Type() protoreflect.EnumType
type ErrorCoder ¶
ErrorCoder is an interface used to obtain an error code from given error within given implementation.