go get code.gopub.tech/errors
- 源码:https://github.com/pub-go/errors
- 镜像:https://gitee.com/pub-go/errors
- 文档:https://pkg.go.dev/code.gopub.tech/errors
Show me the code:
import (
"testing"
"code.gopub.tech/errors"
)
func TestPrint(t *testing.T) {
err1 := errors.New("err1")
err2 := errors.New("err2")
err := errors.Errorf("prefix: %w, %w", err1, err2)
fmt.Printf("%+v\n", err)
}
/* Output 输出:
prefix: err1, err2
(1) attached stack trace
│ -- stack trace:
│ example_test.TestPrint
│ /path/to/new_errors_test.go:65
│ [...repeated from below...]
Next: (2) prefix: err1, err2
Next: (3) err1
│ err2
├─ Wraps: (4) attached stack trace
│ │ -- stack trace:
│ │ example_test.TestPrint
│ │ /path/to/new_errors_test.go:63
│ │ [...repeated from below...]
│ Next: (5) err1
└─ Wraps: (6) attached stack trace
│ -- stack trace:
│ example_test.TestPrint
│ /path/to/new_errors_test.go:64
│ testing.tRunner
│ /usr/local/go/src/testing/testing.go:1576
│ runtime.goexit
│ /usr/local/go/src/runtime/asm_amd64.s:1598
Next: (7) err2
Error types: (1) *errors.withStack (2) *errors.withNewMessage (3) *errors.joinError (4) *errors.withStack (5) *errors.errorString (6) *errors.withStack (7) *errors.errorString
*/