package
1.3.48
Repository: https://github.com/sandwich-go/boost.git
Documentation: pkg.go.dev

# README

xerror

封装error

  • 支持多个 error 封装成单一 error 进行函数参数传递
  • 支持携带错误码信息 error 对象
  • 支持包含调用信息 error 对象
  • 支持 Logic 层异常 error 对象
  • 支持返回最底层的错误信息
  • 支持返回堆栈信息

例子

var arr Array
arr.Push(errors.New("error 1"))
arr.Push(errors.New("error 2"))

if arr.Err() != nil {
    fmt.Println(arr.Error())
}

err := New(WithText("io error"), WithCode(500), WithStack())
errW := Wrap(err, "link error")
errW = Wrap(errW, "session error")
fmt.Println(errW.Error())
fmt.Println(Caller(err.Cause(), 0))

Output:

2 errors occurred:
    #1: error 1
    #2: error 2
    
session error: link error: io error
array_test.go github.com/sandwich-go/boost/xerror.TestArray.func1 35    

# Functions

Caller 返回调用信息.
Cause 返回最底层的错误信息,如果没有实现apiCause,则返回当前错误信息.
Code 返回错误码数据,如果没有实现APICode则根据CodeHandlerForNotAPICode逻辑返回.
ContainsCode 是否有某个 code.
Logic 返回是否是Logic层异常,默认为false.
New 新建 Error 对象.
NewCode 根据错误码和指定的format, args(可为空)构造错误信息.
NewProtoEnum 根据proto enum错误码和指定的format, args(可为空)构造错误信息.
NewText returns an error that formats as the given format and args.
Stack 返回堆栈信息,如果err不支持apiStack,则返回错误本身数据.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
WithStack option func for stack.
No description provided by the author
No description provided by the author
Wrap 封装底层错误,提供另一个错误信息,如果error为nil则返回nil.
WrapCode 封装底层错误,指定错误码,如果error为nil则返回nil.
WrapProtoEnum 封装底层错误,指定proto Enum错误码,如果error为nil则返回nil.

# Variables

No description provided by the author
DotFormatFunc 多个 error,通过 ',' 进行分割输出 如输出: error 1,error 2.
No description provided by the author
No description provided by the author
Errorf returns an error that formats as the given format and args.
No description provided by the author
ListFormatFunc 多个 error,列表输出 如输出: 2 errors occurred: #1: error 1 #2: error 2.

# Structs

Array 错误数组,可以将多个 error 进行组装,并当成 error 进行函数传递或返回.
Error struct.

# Interfaces

APICode Code feature.

# Type aliases

ErrorFormatFunc 格式化 error 数组 调用 Error 时,会将 error 数组进行格式化,默认 ListFormatFunc 可以通过 SetFormatFunc 函数进行设置.
No description provided by the author