errors

package
v1.21.4 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target any) bool

As 检查err和target第一个匹配的err并赋值, 同标准库errors.As

使用到 Unwrap() error 接口
使用到 As(any) bool 接口

func Errorf

func Errorf(format string, args ...any) error

Errorf 使用格式化传入错误消息,返回带追踪的error

func Is

func Is(err, target error) bool

Is 检查err和target是否匹配, 同标准库errors.Is

使用到 Unwrap() error 接口
使用到 Is(error) bool 接口

func New

func New(msg string) error

New 返回带追踪的error

func Trace

func Trace(err error) slog.LogValuer

Trace 获取error日志追踪,返回 slog.LogValuer 接口

func Unwrap

func Unwrap(err error) error

Unwrap 对error Wrap的反向操作

使用到 Unwrap() error 接口

func Wrap

func Wrap(err error, msg ...string) error

Wrap 对error接口进行包装

  1. 如果error是一个nil则返回nil
  2. 如果仅有err参数没有msg参数,进入 3、4步骤,否则包装成一个*wrapError类型返回
  3. 如果error是*wrapError类型,返回原error
  4. 其它类型的error则将error.Error信息作为msg, 包装成一个*wrapError类型返回

func Wrapf

func Wrapf(err error, format string, args ...any) error

Wrapf 对error接口进行包装,如果error是一个nil则返回nil

Types

This section is empty.

Jump to

Keyboard shortcuts

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