-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
64 lines (57 loc) · 1.74 KB
/
example_test.go
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
53
54
55
56
57
58
59
60
61
62
63
64
package errors_test
import (
"fmt"
"github.com/psi59/errors"
)
func ExampleNew() {
err := errors.New("example error")
fmt.Printf("%+v", err)
// Output:
// example error
// at github.com/psi59/errors_test.ExampleNew(example_test.go:9)
}
func ExampleErrorf() {
err := errors.Errorf("example error %d", 123)
fmt.Printf("%+v", err)
// Output:
// example error 123
// at github.com/psi59/errors_test.ExampleErrorf(example_test.go:17)
}
func ExampleWithStack() {
err := errors.New("example error")
err = errors.WithStack(err)
fmt.Printf("%+v", err)
// Output:
//example error
// at github.com/psi59/errors_test.ExampleWithStack(example_test.go:22)
// at github.com/psi59/errors_test.ExampleWithStack(example_test.go:21)
}
func ExampleWrap() {
err := errors.New("example error")
err = errors.Wrap(err, "wrapped")
fmt.Printf("%+v", err)
// Output:
// wrapped: example error
// at github.com/psi59/errors_test.ExampleWrap(example_test.go:36)
// at github.com/psi59/errors_test.ExampleWrap(example_test.go:35)
}
func ExampleWrapf() {
err := errors.New("example error")
err = errors.Wrapf(err, "wrapped %d", 123)
fmt.Printf("%+v", err)
// Output:
// wrapped 123: example error
// at github.com/psi59/errors_test.ExampleWrapf(example_test.go:46)
// at github.com/psi59/errors_test.ExampleWrapf(example_test.go:45)
}
func ExampleWrapWithCause() {
cause := errors.New("cause error")
err := errors.New("example error")
err = errors.WrapWithCause(err, cause)
fmt.Printf("%+v", err)
// Output:
// example error: cause error
// at github.com/psi59/errors_test.ExampleWrapWithCause(example_test.go:57)
// at github.com/psi59/errors_test.ExampleWrapWithCause(example_test.go:56)
// at github.com/psi59/errors_test.ExampleWrapWithCause(example_test.go:55)
}