@@ -19,11 +19,12 @@ package client
19
19
import "C"
20
20
21
21
import (
22
- "errors"
23
22
"math"
24
23
"os"
25
24
"syscall"
26
25
"unsafe"
26
+
27
+ "github.com/pkg/errors"
27
28
)
28
29
29
30
type Client struct {
@@ -38,11 +39,11 @@ var ErrFailToGetStat = errors.New("failed to get stat")
38
39
func New () (* Client , error ) {
39
40
fd , err := syscall .Open ("/dev/chaos" , syscall .O_RDWR , 0 )
40
41
if err != nil {
41
- return nil , err
42
+ return nil , errors . Wrap ( err , "open /dev/chaos" )
42
43
}
43
44
44
45
if C .get_version (C .int (fd )) != COMPATIBLE_VERSION {
45
- return nil , ErrIncompatibleVersion
46
+ return nil , errors . WithStack ( ErrIncompatibleVersion )
46
47
}
47
48
48
49
return & Client {
@@ -61,11 +62,11 @@ func (c *Client) InjectIOEMDelay(devPath string, op int, pidNs uint, delay int64
61
62
if len (devPath ) > 0 {
62
63
info , err := os .Stat (devPath )
63
64
if err != nil {
64
- return 0 , err
65
+ return 0 , errors . Wrapf ( err , "stat file: %s" , devPath )
65
66
}
66
67
stat , ok := info .Sys ().(* syscall.Stat_t )
67
68
if ! ok {
68
- return 0 , ErrFailToGetStat
69
+ return 0 , errors . Wrap ( ErrFailToGetStat , "dev info is not a stat" )
69
70
}
70
71
71
72
dev = C .uint32_t (stat .Rdev )
@@ -76,7 +77,7 @@ func (c *Client) InjectIOEMDelay(devPath string, op int, pidNs uint, delay int64
76
77
77
78
id := C .add_injection (C .int (c .fd ), 0 , unsafe .Pointer (& ioem_injection ), 0 , unsafe .Pointer (& delay_arg ))
78
79
if id < 0 {
79
- return 0 , syscall .Errno (- id )
80
+ return 0 , errors . Wrap ( syscall .Errno (- id ), "add injection" )
80
81
}
81
82
82
83
return int (id ), nil
@@ -85,7 +86,7 @@ func (c *Client) InjectIOEMDelay(devPath string, op int, pidNs uint, delay int64
85
86
func (c * Client ) Recover (id int ) error {
86
87
err := C .del_injection (C .int (c .fd ), C .int (id ))
87
88
if err != 0 {
88
- return syscall .Errno (err )
89
+ return errors . Wrap ( syscall .Errno (err ), "recover injection" )
89
90
}
90
91
91
92
return nil
0 commit comments