errors

package
v1.13.12 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package errors provides errors stack tracking utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target interface{}) bool

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.

The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.

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(interface{}) 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 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 CallDetail

func CallDetail(msg []byte, fn interface{}, args ...interface{}) []byte

CallDetail print a function call shortly.

func Detail deprecated

func Detail(err error) string

Detail is provided for backward compatibility

Deprecated: Use err.Error() instead.

func Err

func Err(err error) error

Err returns the cause error.

func Is

func Is(err, target error) bool

Is reports whether any error in err's chain matches target.

The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.

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 == os.ErrExist }

then Is(MyError{}, os.ErrExist) returns true. See syscall.Errno.Is for an example in the standard library.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound unwraps err and checks it is a *NotFound object or not.

func New

func New(msg string) error

New returns an error that formats as the given text. Each call to New returns a distinct error value even if the text is identical.

func Summary

func Summary(err error) string

Summary returns summary of specified error.

func Unwrap

func Unwrap(err error) error

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.

Types

type ErrorInfo deprecated

type ErrorInfo = Frame

ErrorInfo is provided for backward compatibility

Deprecated: Use Frame instead.

func Info deprecated

func Info(err error, cmd ...interface{}) *ErrorInfo

Info is provided for backward compatibility

Deprecated: Use NewWith instead.

func InfoEx deprecated

func InfoEx(calldepth int, err error, cmd ...interface{}) *ErrorInfo

InfoEx is provided for backward compatibility

Deprecated: Use NewWith instead.

func (*ErrorInfo) AppendErrorDetail

func (p *ErrorInfo) AppendErrorDetail(b []byte) []byte

AppendErrorDetail is provided for backward compatibility

func (*ErrorInfo) Detail

func (p *ErrorInfo) Detail(err error) *ErrorInfo

Detail is provided for backward compatibility

func (*ErrorInfo) ErrorDetail

func (p *ErrorInfo) ErrorDetail() string

ErrorDetail is provided for backward compatibility

func (*ErrorInfo) NestedObject

func (p *ErrorInfo) NestedObject() interface{}

NestedObject is provided for backward compatibility

func (*ErrorInfo) SummaryErr

func (p *ErrorInfo) SummaryErr() error

SummaryErr is provided for backward compatibility

type Frame

type Frame struct {
	Err  error
	Func string
	Args []interface{}
	Code string
	File string
	Line int
}

Frame represents an error frame.

func NewFrame

func NewFrame(err error, code, file string, line int, fn string, args ...interface{}) *Frame

NewFrame creates a new error frame.

func NewWith

func NewWith(err error, code string, n int, fn string, args ...interface{}) *Frame

NewWith creates a new error frame.

func (*Frame) Error

func (p *Frame) Error() string

func (*Frame) Format

func (p *Frame) Format(s fmt.State, verb rune)

Format is required by fmt.Formatter

func (*Frame) Summary

func (p *Frame) Summary() string

func (*Frame) Unwrap

func (p *Frame) Unwrap() error

Unwrap provides compatibility for Go 1.13 error chains.

type List

type List []error

List represents a list of errors.

func (*List) Add

func (p *List) Add(err error)

Add adds an error into the error list.

func (List) Error

func (p List) Error() string

Error returns all errors joined with "\n".

func (List) Format

func (p List) Format(s fmt.State, verb rune)

Format is required by fmt.Formatter

func (List) Summary

func (p List) Summary() string

Summary returns summary of all errors.

func (List) ToError

func (p List) ToError() error

ToError converts error list into an error. If list length == 0, it returns nil; If list length == 1, it returns the list item. If list length > 1, it returns the error list itself.

type NotFound

type NotFound struct {
	Category string
}

NotFound is a generic NotFound error.

func (*NotFound) Error

func (p *NotFound) Error() string

Jump to

Keyboard shortcuts

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