Documentation
¶
Overview ¶
Package errz provides errors and error codes.
Index ¶
- Variables
- func As(err error, target any) bool
- func Is(err error, targets ...error) bool
- func Join(errs ...error) error
- func NewFactory() *factory
- func ReplaceGlobal(f *factory) error
- func Unwrap(err error) error
- type Code
- type Error
- func (e *Error) Code() Code
- func (e *Error) Error() string
- func (e *Error) IsEmpty() bool
- func (e *Error) Location() *location
- func (e *Error) Message() string
- func (e *Error) Meta() Metadata
- func (e *Error) StackTrace() []runtime.Frame
- func (e *Error) String() string
- func (e *Error) Timestamp() *time.Time
- func (e *Error) Unwrap() []error
- func (e *Error) With(key string, value any) *Error
- func (e *Error) WithLocation() *Error
- func (e *Error) WithMany(pairs ...any) *Error
- func (e *Error) WithTime() *Error
- func (e *Error) WithTrace(skip int) *Error
- func (e *Error) Wrap(err error) *Error
- type Metadata
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCanceled indicates the operation was canceled. ErrCanceled = E(Canceled) // ErrUnknown indicates the operation failed for an unknown reason. ErrUnknown = E(Unknown) // ErrInvalidArgument indicates client supplied an invalid argument. ErrInvalidArgument = E(InvalidArgument) // ErrDeadlineExceeded indicates deadline expired before operation could complete. ErrDeadlineExceeded = E(DeadlineExceeded) // ErrNotFound indicates requested entity was not found. ErrNotFound = E(NotFound) // ErrAlreadyExists indicates client attempted to create an entity that already exists. ErrAlreadyExists = E(AlreadyExists) // ErrPermissionDenied indicates caller does not have permission. ErrPermissionDenied = E(PermissionDenied) // ErrResourceExhausted indicates some resource has been exhausted. ErrResourceExhausted = E(ResourceExhausted) // ErrFailedPrecondition indicates system is not in state required for operation. ErrFailedPrecondition = E(FailedPrecondition) // ErrAborted indicates operation was aborted by the system. ErrAborted = E(Aborted) // ErrOutOfRange indicates operation was attempted past the valid range. ErrOutOfRange = E(OutOfRange) // ErrUnimplemented indicates operation is not implemented. ErrUnimplemented = E(Unimplemented) // ErrInternal indicates some invariants expected by underlying system have been broken. ErrInternal = E(Internal) ErrUnavailable = E(Unavailable) // ErrDataLoss indicates operation resulted in unrecoverable data loss. ErrDataLoss = E(DataLoss) // ErrUnauthenticated indicates request does not have valid authentication. ErrUnauthenticated = E(Unauthenticated) )
Functions ¶
func As ¶
As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true. Otherwise, it returns false.
func NewFactory ¶ added in v0.5.0
func NewFactory() *factory
NewFactory creates a new error factory.
func ReplaceGlobal ¶ added in v0.5.0
func ReplaceGlobal(f *factory) error
ReplaceGlobal changes the global error factory.
Types ¶
type Code ¶ added in v0.2.0
type Code uint32
Code represents an error code.
const ( // OK is returned on success. OK Code = 0 // Canceled indicates that the operation was Canceled, typically by the caller. Canceled Code = 1 // Unknown indicates that the operation failed for an Unknown reason. Unknown Code = 2 // InvalidArgument indicates that client supplied an invalid argument. InvalidArgument Code = 3 // DeadlineExceeded indicates that deadline expired before the operation could complete. DeadlineExceeded Code = 4 // NotFound indicates that some requested entity (for example, a file or directory) was not found. NotFound Code = 5 // AlreadyExists indicates that client attempted to create an entity (e.g, a file or directory) that already exists. AlreadyExists Code = 6 // PermissionDenied indicates that the caller doesn't have permission to execute the specified operation. PermissionDenied Code = 7 // ResourceExhausted indicates that some resource has been exhausted. // For example, a per-user quota may be exhausted or the entire file system may be full. ResourceExhausted Code = 8 // FailedPrecondition indicates that the system is not in a state required for the operation's execution. FailedPrecondition Code = 9 // Aborted indicates that operation was Aborted by the system, // usually because of a concurrency issue such as a sequencer check failure or transaction abort. Aborted Code = 10 // OutOfRange indicates that the operation was attempted past the valid range (for example, seeking past end-of-file). OutOfRange Code = 11 // Unimplemented indicates that the operation isn't implemented, supported, or enabled in this service. Unimplemented Code = 12 // Internal indicates that some invariants expected by the underlying system have been broken. // This code is reserved for serious errors. Internal Code = 13 // This is usually temporary, so clients can back off and retry idempotent operations. Unavailable Code = 14 // DataLoss indicates that the operation has resulted in unrecoverable data loss or corruption. DataLoss Code = 15 // Unauthenticated indicates that the request does not have valid authentication credentials for the operation. Unauthenticated Code = 16 )
func CodeOf ¶
CodeOf returns the error's status code if it is or wraps an *Error and Unknown otherwise.
func (*Code) MarshalText ¶ added in v0.2.0
MarshalText implements encoding.TextMarshaler.
func (*Code) UnmarshalText ¶ added in v0.2.0
UnmarshalText implements encoding.TextUnmarshaler.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error represents a structured error.
func (*Error) Location ¶ added in v0.2.0
func (e *Error) Location() *location
Location returns the caller's location when the error was created.
func (*Error) StackTrace ¶ added in v0.2.0
StackTrace returns the error's stack trace.
func (*Error) WithLocation ¶
WithLocation adds the caller's location to the error.
func (*Error) WithMany ¶ added in v0.4.1
WithMany adds multiple metadata key-value pairs to the error.
type Metadata ¶ added in v0.2.1
type Metadata []detail
Metadata is a collection of metadata details.