Documentation
¶
Index ¶
- Constants
- Variables
- func As(err error, target any) bool
- func Code(err error) int
- func Errorf(code int, reason, format string, a ...any) error
- func Is(err, target error) bool
- func Reason(err error) string
- func Unwrap(err error) error
- type Error
- type Status
- func (*Status) Descriptor() ([]byte, []int)deprecated
- func (x *Status) GetCode() int32
- func (x *Status) GetMessage() string
- func (x *Status) GetMetadata() map[string]string
- func (x *Status) GetReason() string
- func (*Status) ProtoMessage()
- func (x *Status) ProtoReflect() protoreflect.Message
- func (x *Status) Reset()
- func (x *Status) String() string
Constants ¶
const ( UnknownCode = 500 UnknownReason = "" )
Variables ¶
var (
// optional int32 code = 51002;
E_Code = &file_errors_proto_extTypes[1]
)
Extension fields to descriptorpb.EnumValueOptions.
var (
// optional int32 default_code = 51001;
E_DefaultCode = &file_errors_proto_extTypes[0]
)
Extension fields to descriptorpb.EnumOptions.
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.
Types ¶
type Error ¶
type Error struct {
Status
// contains filtered or unexported fields
}
func (*Error) GRPCStatus ¶
type Status ¶
type Status struct {
Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
Reason string `protobuf:"bytes,2,opt,name=reason,proto3" json:"reason,omitempty"`
Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"`
Metadata map[string]string `` /* 143-byte string literal not displayed */
// contains filtered or unexported fields
}
func (*Status) Descriptor
deprecated
func (*Status) GetMessage ¶
func (*Status) GetMetadata ¶
func (*Status) ProtoMessage ¶
func (*Status) ProtoMessage()
func (*Status) ProtoReflect ¶
func (x *Status) ProtoReflect() protoreflect.Message