-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow_stack_test.go
More file actions
52 lines (45 loc) · 1.48 KB
/
Copy pathshow_stack_test.go
File metadata and controls
52 lines (45 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package examples
import (
"errors"
"fmt"
"github.com/gomooth/xerror"
)
func ExampleError_unwrap() {
err := xerror.New("xerror")
// Unwrap 返回内部 error,使用 %+v 可查看栈信息
unwrapped := err.Unwrap()
fmt.Println(unwrapped != nil)
// 栈追踪输出包含文件路径,不同机器不同,不使用 Output 注释验证
fmt.Printf("%+v\n", unwrapped)
}
func ExampleError_unwrap_with_wrap() {
err := xerror.New("xerror")
werr := xerror.Wrap(err, "wrap message")
// 栈追踪输出包含文件路径,不同机器不同,不使用 Output 注释验证
fmt.Printf("%+v\n", werr.Unwrap())
}
func ExampleError_unwrap_with_error() {
err := errors.New("xerror")
werr := xerror.Wrap(err, "wrap message")
// 栈追踪输出包含文件路径,不同机器不同,不使用 Output 注释验证
fmt.Printf("%+v\n", werr.Unwrap())
}
func ExampleError_with_fields() {
err := xerror.New("xerror").WithFields(
xerror.F("foo", "bar"),
xerror.F("bar", 0.79),
xerror.F("struct", struct{ Foo string }{Foo: "bar"}),
)
// 栈追踪输出包含文件路径,不同机器不同,不使用 Output 注释验证
fmt.Printf("%+v\n", err)
}
func ExampleError_with_fields_wrap() {
err := xerror.New("xerror").WithFields(
xerror.F("foo", "bar"),
xerror.F("bar", 0.79),
xerror.F("struct", struct{ Foo string }{Foo: "bar"}),
)
werr := xerror.Wrap(err, "wrap message")
// 栈追踪输出包含文件路径,不同机器不同,不使用 Output 注释验证
fmt.Printf("%+v\n", werr)
}