-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_examples_test.go
57 lines (50 loc) · 950 Bytes
/
error_examples_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
package serrors_test
import (
"fmt"
"github.com/Eun/serrors"
)
func ExampleNew() {
name := "Joe"
if name == "alice" {
panic(serrors.New("invalid name").With("name", name))
}
fmt.Println(name)
// Output:
// Joe
}
func ExampleErrorf() {
name := "Joe"
if name == "alice" {
panic(serrors.Errorf("invalid name %q", name).With("name", name))
}
fmt.Println(name)
// Output:
// Joe
}
func ExampleWrap() {
name := "Joe"
if err := validateUserName(name); err != nil {
panic(serrors.Wrap(err, "invalid name").With("name", name))
}
fmt.Println(name)
// Output:
// Joe
}
func ExampleWrapf() {
name := "Joe"
if err := validateUserName(name); err != nil {
panic(serrors.Wrapf(err, "invalid name %q", name).With("name", name))
}
fmt.Println(name)
// Output:
// Joe
}
func ExampleWith() {
name := "Joe"
if name == "alice" {
panic(serrors.New("invalid name").With("name", name))
}
fmt.Println(name)
// Output:
// Joe
}