Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var MaxStackDepth = 5
最大可纪录的调用堆栈的深度
Functions ¶
Types ¶
type CodedError ¶
CodedError 具有code的错误类型
Example ¶
package main import ( "fmt" "github.com/recallsong/go-utils/errorx" ) func main() { err := errorx.NewCodedError(400, "bad request") fmt.Println(err) }
Output: 400, bad request
type Errors ¶
type Errors []error
Errors is a slice of errors implementing the error interface.
func (Errors) MaybeUnwrap ¶
MaybeUnwrap returns nil if len(errs) is 0. It returns the first and only contained error as error if len(errs is 1). In all other cases, it returns the Errors directly. This is helpful for returning a Errors in a way that only uses the Errors if needed.
type MultiError ¶
MultiError 多个错误的集合类型
Example ¶
package main import ( "fmt" "github.com/recallsong/go-utils/errorx" ) func main() { err0 := errorx.New("error 0") err1 := errorx.New("error 1") err2 := errorx.New("error 2") errs := errorx.NewMultiError(err0, err1, err2) fmt.Println(errs) var empty errorx.Errors fmt.Println(empty.MaybeUnwrap()) }
Output: 3 error(s) occurred: * error 0 * error 1 * error 2 <nil>
type StringError ¶
type StringError string
StringError 简单的字符串型错误
Example ¶
package main import ( "fmt" "github.com/recallsong/go-utils/errorx" ) func main() { var err error = errorx.New("this is error message") fmt.Println(err) }
Output: this is error message
func (StringError) Error ¶
func (err StringError) Error() string
type TracedError ¶
type TracedError interface { error Callers() []uintptr // 返回堆栈调用信息 Unpack() error // 返回去掉堆栈调用信息的错误 }
Example ¶
package main import ( "fmt" "github.com/recallsong/go-utils/errorx" ) func main() { err := errorx.NewTracedError("this is error message") fmt.Println(err) }
Output: this is error message : * [example_test.go:43] errorx_test.ExampleTracedError * [example.go:122] testing.runExample * [example.go:46] testing.runExamples * [testing.go:922] testing.(*M).Run * [_testmain.go:56] main.main
func NewTracedError ¶
func NewTracedError(err interface{}) TracedError
NewTracedError 创建一个具有堆栈调用信息的错误
Click to show internal directories.
Click to hide internal directories.