Documentation
¶
Index ¶
- func As(err error, target any) bool
- func Cause(err error) error
- func Detail(err error) string
- func ElideSharedStackTraceSuffix(prevStack, newStack []uintptr) ([]uintptr, bool)
- func Errorf(format string, args ...any) error
- func FormatError(err error, s fmt.State, verb rune)
- func GetStackTrace(err error) (st []uintptr, ok bool)
- func Is(err, target error) bool
- func Join(errs ...error) error
- func New(msg string) error
- func StackDetail(st []uintptr) string
- func Unwrap(err error) error
- func UnwrapAll(err error) error
- func UnwrapMulti(err error) []error
- func UnwrapOnce(err error) error
- func WithMessage(err error, msg string) error
- func WithMessagef(err error, format string, args ...any) error
- func WithSecondary(err, secondary error) error
- func WithStack(err error) error
- func Wrap(err error, msg string) error
- func Wrapf(err error, format string, args ...any) error
- type ErrorPrinter
- type FormattableError
- type Printer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ElideSharedStackTraceSuffix ¶
ElideSharedStackTraceSuffix 省略共同的堆栈
func FormatError ¶
FormatError 能够识别格式化动词智能打印。 当一个错误类型在实现 fmt.Formatter 接口时,可以直接转发给本函数。
如果传入的错误类型实现了 errors.Formatter 接口, FormatError 会使用‘按 s, verb 配置好的 Printer’ 调用它的 FormatError 方法。
否则,如果错误类型是一个包装类型(实现了 Cause/Unwrap) FormatError 会输出包装错误的附加信息,并递归地处理其内部错误。
其他情况,直接打印 Error() 文本。
func GetStackTrace ¶
GetStackTrace 获取错误上附加的堆栈 兼容 pkg/errors, cockroachdb/errors (通过反射)
func UnwrapMulti ¶
func UnwrapOnce ¶
func WithMessagef ¶
WithMessagef 给错误添加一个指定格式的前缀注解信息
func WithSecondary ¶
WithSecondary 给错误附加一个次要错误。 次要错误仅在使用 %+v 格式化动词时才会打印
Types ¶
type ErrorPrinter ¶
type ErrorPrinter interface { error // PrintError 输出错误信息. // 使用 Print, Printf 输出的错误信息总是可见; // 使用 PrintDetail, PrintDetailf 输出错误信息仅在 %+v 格式下可见. // // 返回的 next error 如果为 nil 代表在拼接简单消息时,仅输出本 error 而忽略 cause. // // 如一个 withPrefix 结构的错误实例,应在 Print 自身消息后,再返回 cause; // 而一个 withNewMessage 结构的错误实例,在 Print 自身消息后,会返回 nil. // // 在 %+v 详细格式下,不管返回的 next error 是否为 nil,都会输出其 cause. PrintError(p Printer) (next error) }
type FormattableError ¶
func Formattable ¶
func Formattable(err error) FormattableError
Formattable 将一个错误包装为 fmt.Formatter 标准库中的 wrapErrors, joinerrors 并没有实现 fmt.Formatter 接口 使用这个帮助函数可以让那些错误类型也支持智能打印功能(自动解析 cause 等)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.