Documentation
¶
Index ¶
- Constants
- Variables
- func As(err error, target any) bool
- func Errorf(code int, reason, format string, a ...any) error
- func Is(err, target error) bool
- func Marshal(code codes.Code, err error) error
- func New(code int, reason, message string) error
- func Newf(code int, reason, format string, a ...any) error
- func RegisterChainableErrorType(ty string, fn func(string, []byte) error) error
- func Unmarshal(err error) error
- func Unwrap(err error) error
- func UnwrapGRPCResponse[T any](data T, err error) (T, error)
- func WrpGRPCResponse[T any](data T, err error) (T, error)
- type AdvancedError
- type Chainable
- type ErrorChain
- type ErrorChainNode
- func (*ErrorChainNode) Descriptor() ([]byte, []int)deprecated
- func (x *ErrorChainNode) GetData() []byte
- func (x *ErrorChainNode) GetMessage() string
- func (x *ErrorChainNode) GetType() string
- func (x *ErrorChainNode) GetWrapped() *ErrorChainNode
- func (*ErrorChainNode) ProtoMessage()
- func (x *ErrorChainNode) ProtoReflect() protoreflect.Message
- func (x *ErrorChainNode) Reset()
- func (x *ErrorChainNode) String() string
- type ErrorStatus
- func (*ErrorStatus) Descriptor() ([]byte, []int)deprecated
- func (x *ErrorStatus) GetCode() int32
- func (x *ErrorStatus) GetMessage() string
- func (x *ErrorStatus) GetMetadata() map[string]string
- func (x *ErrorStatus) GetReason() string
- func (x *ErrorStatus) GetStatus() uint32
- func (*ErrorStatus) ProtoMessage()
- func (x *ErrorStatus) ProtoReflect() protoreflect.Message
- func (x *ErrorStatus) Reset()
- func (x *ErrorStatus) String() string
- type StandardError
- func (se *StandardError) Cause() error
- func (se *StandardError) Clone() *StandardError
- func (se *StandardError) Code() int32
- func (se *StandardError) Error() string
- func (se *StandardError) Is(target error) bool
- func (se *StandardError) Marshal() ([]byte, error)
- func (se *StandardError) Message() string
- func (se *StandardError) Metadata() map[string]string
- func (se *StandardError) Reason() string
- func (se *StandardError) Status() codes.Code
- func (se *StandardError) Type() string
- func (se *StandardError) Unwrap() error
- func (se *StandardError) WithCause(cause error) AdvancedError
- func (se *StandardError) WithCode(code int32) AdvancedError
- func (se *StandardError) WithMessage(message string) AdvancedError
- func (se *StandardError) WithMetadata(metadata map[string]string) AdvancedError
- func (se *StandardError) WithReason(reason string) AdvancedError
- func (se *StandardError) WithStatus(status codes.Code) AdvancedError
- func (se *StandardError) Wrap(err error) error
Constants ¶
const CHAINABLE_ERROR_TYPE_GOLANG = "errorString"
const CHAINABLE_ERROR_TYPE_STANDARD = _STANDARD_ERROR_TYPE
Variables ¶
var ( // optional int32 default_code = 51001; E_DefaultCode = &file_errors_proto_extTypes[0] // optional uint32 default_status = 51002; E_DefaultStatus = &file_errors_proto_extTypes[1] )
Extension fields to descriptorpb.EnumOptions.
var ( // optional int32 code = 52001; E_Code = &file_errors_proto_extTypes[2] // optional uint32 status = 52002; E_Status = &file_errors_proto_extTypes[3] )
Extension fields to descriptorpb.EnumValueOptions.
var File_errors_proto protoreflect.FileDescriptor
Functions ¶
func As ¶
As finds the first error in err's tree that matches target, and if one is found, sets target to that error value and returns true. Otherwise, it returns false.
The tree consists of err itself, followed by the errors obtained by repeatedly calling its Unwrap() error or Unwrap() []error method. When err wraps multiple errors, As examines err followed by a depth-first traversal of its children.
An error matches target if the error's concrete value is assignable to the value pointed to by target, or if the error has a method As(any) bool such that As(target) returns true. In the latter case, the As method is responsible for setting target.
An error type might provide an As method so it can be treated as if it were a different error type.
As panics if target is not a non-nil pointer to either a type that implements error, or to any interface type.
func Is ¶
Is reports whether any error in err's tree matches target.
The tree consists of err itself, followed by the errors obtained by repeatedly calling its Unwrap() error or Unwrap() []error method. When err wraps multiple errors, Is examines err followed by a depth-first traversal of its children.
An error is considered to match a target if it is equal to that target or if it implements a method Is(error) bool such that Is(target) returns true.
An error type might provide an Is method so it can be treated as equivalent to an existing error. For example, if MyError defines
func (m MyError) Is(target error) bool { return target == fs.ErrExist }
then Is(MyError{}, fs.ErrExist) returns true. See syscall.Errno.Is for an example in the standard library. An Is method should only shallowly compare err and the target and not call Unwrap on either.
func RegisterChainableErrorType ¶ added in v0.4.0
func Unwrap ¶
Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil.
Unwrap only calls a method of the form "Unwrap() error". In particular Unwrap does not unwrap errors returned by [Join].
func UnwrapGRPCResponse ¶ added in v0.4.1
func WrpGRPCResponse ¶ added in v0.4.1
Types ¶
type AdvancedError ¶ added in v0.4.1
type AdvancedError interface {
Unwrap() error
Is(error) bool
// getters
Status() codes.Code
Code() int32
Reason() string
Message() string
Metadata() map[string]string
Cause() error
// setters
WithStatus(codes.Code) AdvancedError
WithCode(int32) AdvancedError
WithReason(string) AdvancedError
WithMessage(string) AdvancedError
WithMetadata(map[string]string) AdvancedError
WithCause(error) AdvancedError
Chainable
}
type ErrorChain ¶ added in v0.4.0
type ErrorChain struct {
Root *ErrorChainNode `protobuf:"bytes,1,opt,name=root,proto3" json:"root,omitempty"`
// contains filtered or unexported fields
}
func (*ErrorChain) Descriptor
deprecated
added in
v0.4.0
func (*ErrorChain) Descriptor() ([]byte, []int)
Deprecated: Use ErrorChain.ProtoReflect.Descriptor instead.
func (*ErrorChain) GetRoot ¶ added in v0.4.0
func (x *ErrorChain) GetRoot() *ErrorChainNode
func (*ErrorChain) ProtoMessage ¶ added in v0.4.0
func (*ErrorChain) ProtoMessage()
func (*ErrorChain) ProtoReflect ¶ added in v0.4.0
func (x *ErrorChain) ProtoReflect() protoreflect.Message
func (*ErrorChain) Reset ¶ added in v0.4.0
func (x *ErrorChain) Reset()
func (*ErrorChain) String ¶ added in v0.4.0
func (x *ErrorChain) String() string
type ErrorChainNode ¶ added in v0.4.0
type ErrorChainNode struct {
Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
Wrapped *ErrorChainNode `protobuf:"bytes,4,opt,name=wrapped,proto3" json:"wrapped,omitempty"`
// contains filtered or unexported fields
}
func (*ErrorChainNode) Descriptor
deprecated
added in
v0.4.0
func (*ErrorChainNode) Descriptor() ([]byte, []int)
Deprecated: Use ErrorChainNode.ProtoReflect.Descriptor instead.
func (*ErrorChainNode) GetData ¶ added in v0.4.0
func (x *ErrorChainNode) GetData() []byte
func (*ErrorChainNode) GetMessage ¶ added in v0.4.0
func (x *ErrorChainNode) GetMessage() string
func (*ErrorChainNode) GetType ¶ added in v0.4.0
func (x *ErrorChainNode) GetType() string
func (*ErrorChainNode) GetWrapped ¶ added in v0.4.0
func (x *ErrorChainNode) GetWrapped() *ErrorChainNode
func (*ErrorChainNode) ProtoMessage ¶ added in v0.4.0
func (*ErrorChainNode) ProtoMessage()
func (*ErrorChainNode) ProtoReflect ¶ added in v0.4.0
func (x *ErrorChainNode) ProtoReflect() protoreflect.Message
func (*ErrorChainNode) Reset ¶ added in v0.4.0
func (x *ErrorChainNode) Reset()
func (*ErrorChainNode) String ¶ added in v0.4.0
func (x *ErrorChainNode) String() string
type ErrorStatus ¶ added in v0.4.1
type ErrorStatus struct {
// grpc codes.Code
Status uint32 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"`
Code int32 `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
Reason string `protobuf:"bytes,3,opt,name=reason,proto3" json:"reason,omitempty"`
Message string `protobuf:"bytes,4,opt,name=message,proto3" json:"message,omitempty"`
Metadata map[string]string `` /* 143-byte string literal not displayed */
// contains filtered or unexported fields
}
func (*ErrorStatus) Descriptor
deprecated
added in
v0.4.1
func (*ErrorStatus) Descriptor() ([]byte, []int)
Deprecated: Use ErrorStatus.ProtoReflect.Descriptor instead.
func (*ErrorStatus) GetCode ¶ added in v0.4.1
func (x *ErrorStatus) GetCode() int32
func (*ErrorStatus) GetMessage ¶ added in v0.4.1
func (x *ErrorStatus) GetMessage() string
func (*ErrorStatus) GetMetadata ¶ added in v0.4.1
func (x *ErrorStatus) GetMetadata() map[string]string
func (*ErrorStatus) GetReason ¶ added in v0.4.1
func (x *ErrorStatus) GetReason() string
func (*ErrorStatus) GetStatus ¶ added in v0.4.1
func (x *ErrorStatus) GetStatus() uint32
func (*ErrorStatus) ProtoMessage ¶ added in v0.4.1
func (*ErrorStatus) ProtoMessage()
func (*ErrorStatus) ProtoReflect ¶ added in v0.4.1
func (x *ErrorStatus) ProtoReflect() protoreflect.Message
func (*ErrorStatus) Reset ¶ added in v0.4.1
func (x *ErrorStatus) Reset()
func (*ErrorStatus) String ¶ added in v0.4.1
func (x *ErrorStatus) String() string
type StandardError ¶ added in v0.4.1
type StandardError struct {
// contains filtered or unexported fields
}
func NewStandardError ¶ added in v0.4.1
func NewStandardError(status codes.Code, code int, reason, message string) *StandardError
func NewStandardErrorFromError ¶ added in v0.4.1
func NewStandardErrorFromError(err error) *StandardError
func NewStandardErrorf ¶ added in v0.4.1
func (*StandardError) Cause ¶ added in v0.4.1
func (se *StandardError) Cause() error
func (*StandardError) Clone ¶ added in v0.4.1
func (se *StandardError) Clone() *StandardError
func (*StandardError) Code ¶ added in v0.4.1
func (se *StandardError) Code() int32
func (*StandardError) Error ¶ added in v0.4.1
func (se *StandardError) Error() string
func (*StandardError) Is ¶ added in v0.4.1
func (se *StandardError) Is(target error) bool
func (*StandardError) Marshal ¶ added in v0.4.1
func (se *StandardError) Marshal() ([]byte, error)
func (*StandardError) Message ¶ added in v0.4.1
func (se *StandardError) Message() string
func (*StandardError) Metadata ¶ added in v0.4.1
func (se *StandardError) Metadata() map[string]string
func (*StandardError) Reason ¶ added in v0.4.1
func (se *StandardError) Reason() string
func (*StandardError) Status ¶ added in v0.4.1
func (se *StandardError) Status() codes.Code
func (*StandardError) Type ¶ added in v0.4.1
func (se *StandardError) Type() string
func (*StandardError) Unwrap ¶ added in v0.4.1
func (se *StandardError) Unwrap() error
func (*StandardError) WithCause ¶ added in v0.4.1
func (se *StandardError) WithCause(cause error) AdvancedError
func (*StandardError) WithCode ¶ added in v0.4.1
func (se *StandardError) WithCode(code int32) AdvancedError
func (*StandardError) WithMessage ¶ added in v0.4.1
func (se *StandardError) WithMessage(message string) AdvancedError
func (*StandardError) WithMetadata ¶ added in v0.4.1
func (se *StandardError) WithMetadata(metadata map[string]string) AdvancedError
func (*StandardError) WithReason ¶ added in v0.4.1
func (se *StandardError) WithReason(reason string) AdvancedError
func (*StandardError) WithStatus ¶ added in v0.4.1
func (se *StandardError) WithStatus(status codes.Code) AdvancedError
func (*StandardError) Wrap ¶ added in v0.4.1
func (se *StandardError) Wrap(err error) error