Documentation
¶
Overview ¶
Package errors
使用[github.com/juju/errors,github.com/pkg/errors]时加入一些当前项目的需求
Index ¶
- func Annotate(other error, message string, args ...interface{}) error
- func Annotatef(other error, format string, args ...interface{}) errordeprecated
- func As(err error, target interface{}) bool
- func Cause(err error) error
- func Chain(err error) string
- func Details(err error) string
- func ErrorStack(err error) stringdeprecated
- func Errorf(format string, args ...interface{}) errordeprecated
- func Format(format string, args ...interface{}) error
- func Is(err, target error) bool
- func New(args ...interface{}) error
- func PC(pc uintptr) runtime.Frame
- func Position() error
- func Stacks(err error) string
- func Trace(other error) error
- func Unwrap(err error) error
- func WithMessage(err error, message string, args ...interface{}) errordeprecated
- func WithMessagef(err error, format string, args ...interface{}) errordeprecated
- func WithStack(err error) errordeprecated
- type Annotator
- type Caller
- type Callers
- type Err
- type Location
- type Locator
- type LocatorError
- type Messenger
- type UnWrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chain ¶
Chain 会循环 Unwrap ,找到 error 的每层包装, 并格式化(包含调用栈信息和注释信息)到单行
go run ./errors/_examples/chain/main.go
: EOF
4980726 .../smallsung/gopkg/errors/_examples/chain/main.go:12:
4980741 .../smallsung/gopkg/errors/_examples/chain/main.go:13: 注释信息1
4980805 .../smallsung/gopkg/errors/_examples/chain/main.go:14:
4980830 .../smallsung/gopkg/errors/_examples/chain/main.go:15: 注释信息2
func Details ¶
Details 展示完整的错误信息. 它包含 最初错误信息,错误包装信息,最内部实现 Callers 的 error 的堆栈
go run ./errors/_examples/details/main.go
error:
EOF
errors:
: EOF
7867990 .../smallsung/gopkg/errors/_examples/details/main.go:12:
7868005 .../smallsung/gopkg/errors/_examples/details/main.go:13: 注释信息1
7868069 .../smallsung/gopkg/errors/_examples/details/main.go:14:
7868094 .../smallsung/gopkg/errors/_examples/details/main.go:15: 注释信息2
stacks:
7867990 .../smallsung/gopkg/errors/_examples/details/main.go:12: main.main
7377781 .../src/runtime/proc.go:225: runtime.main
7563840 .../src/runtime/asm_amd64.s:1371: runtime.goexit
func ErrorStack
deprecated
func New ¶
func New(args ...interface{}) error
New 是标准库的替代品.它返回一个包含调用栈信息的错误.
New()
New(message string)
New(format string, args ...interface{})
func WithMessage
deprecated
func WithMessagef
deprecated
Types ¶
type Err ¶
type Err = LocatorError
Err github.com/juju/errors.Err
func NewErrWithCause ¶
NewErrWithCause github.com/juju/errors.NewErrWithCause
type Locator ¶
type Locator interface {
//SetLocation 设置调用包装的文件和行.供 locator 调用
SetLocation(skip int)
}
func NewLocator ¶
func NewLocator() Locator
type LocatorError ¶
type LocatorError interface {
error
Locator
// Formatter
// %s 输出最内层错误消息
// %v 输出包含注释(如果有)错误消息。 annotate: error
// %+v 输出错误链 pc file:line: error
fmt.Formatter
Caller
Callers
Locator
Annotator
UnWrapper
// contains filtered or unexported methods
}
func NewCauserAnnotatorLocatorError ¶
func NewCauserAnnotatorLocatorError(cause error, format string, args ...interface{}) LocatorError
func NewCauserLocatorError ¶
func NewCauserLocatorError(cause error) LocatorError
func NewLocatorError ¶
func NewLocatorError(format string, args ...interface{}) LocatorError
Source Files
¶
Click to show internal directories.
Click to hide internal directories.