errors

package
v1.10.6 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2020 License: Apache-2.0 Imports: 5 Imported by: 19

Documentation

Overview

Package errors provides errors stack tracking utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArgsDetail added in v1.10.6

func ArgsDetail(b []byte, args []interface{}) []byte

ArgsDetail print args shortly.

func As added in v1.10.4

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 Detail

func Detail(err error) string

Detail is provided for backward compatibility

func Err

func Err(err error) error

Err returns the cause error.

func Is added in v1.10.4

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 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 Unwrap added in v1.10.4

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

type ErrorInfo = Frame

ErrorInfo is provided for backward compatibility

func Info

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

Info is provided for backward compatibility

func InfoEx

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

InfoEx is provided for backward compatibility

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 added in v1.10.4

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

Frame represents an error frame.

func NewFrame added in v1.10.4

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

NewFrame creates a new error frame.

func (*Frame) Error added in v1.10.4

func (p *Frame) Error() string

func (*Frame) Format added in v1.10.4

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

Format is required by fmt.Formatter

func (*Frame) Unwrap added in v1.10.4

func (p *Frame) Unwrap() error

Unwrap provides compatibility for Go 1.13 error chains.

Jump to

Keyboard shortcuts

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