-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_test.go
More file actions
85 lines (70 loc) · 1.82 KB
/
example_test.go
File metadata and controls
85 lines (70 loc) · 1.82 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package cling_test
import (
"errors"
"fmt"
"golang.org/x/xerrors"
"github.com/jbowes/cling"
)
func Example() {
// All funcs in this package print error chains
err := errors.New("an error")
wrapped := cling.Wrap(err, "wrapped")
rewrapped := cling.Wrap(wrapped, "re-wrapped")
fmt.Printf("%v", rewrapped) // or use %+v to print the stack frames
// Output: re-wrapped: wrapped: an error
}
func Example_nil() {
// All funcs in this package return nil when passed a nil error.
err := error(nil)
wrapped := cling.Wrap(err, "wrapped")
fmt.Print(wrapped)
// Output: <nil>
}
func ExampleNew() {
err := cling.New("an error")
fmt.Print(err)
// Output: an error
}
func ExampleErrorf() {
err := cling.Errorf("an error for %s", "you")
fmt.Print(err)
// Output: an error for you
}
func ExampleWrap() {
err := errors.New("an error")
wrapped := cling.Wrap(err, "wrapped")
fmt.Print(wrapped)
// Output: wrapped: an error
}
func ExampleWrap_is() {
err := errors.New("an error")
wrapped := cling.Wrap(err, "wrapped")
// Wrapped errors can be programatically inspected
fmt.Print(xerrors.Is(wrapped, err))
// Output: true
}
func ExampleWrapf() {
err := errors.New("an error")
wrapped := cling.Wrapf(err, "wrapped, especially for %s", "you")
fmt.Print(wrapped)
// Output: wrapped, especially for you: an error
}
func ExampleSeal() {
err := errors.New("an error")
sealed := cling.Seal(err, "sealed")
fmt.Print(sealed)
// Output: sealed: an error
}
func ExampleSeal_is() {
err := errors.New("an error")
sealed := cling.Seal(err, "sealed")
// Sealed errors are opaque for programmatic inspection
fmt.Print(xerrors.Is(sealed, err))
// Output: false
}
func ExampleSealf() {
err := errors.New("an error")
sealed := cling.Sealf(err, "sealed, especially for %s", "you")
fmt.Print(sealed)
// Output: sealed, especially for you: an error
}