@@ -19,11 +19,12 @@ package client
1919import "C"
2020
2121import (
22- "errors"
2322 "math"
2423 "os"
2524 "syscall"
2625 "unsafe"
26+
27+ "github.com/pkg/errors"
2728)
2829
2930type Client struct {
@@ -38,11 +39,11 @@ var ErrFailToGetStat = errors.New("failed to get stat")
3839func New () (* Client , error ) {
3940 fd , err := syscall .Open ("/dev/chaos" , syscall .O_RDWR , 0 )
4041 if err != nil {
41- return nil , err
42+ return nil , errors . Wrap ( err , "open /dev/chaos" )
4243 }
4344
4445 if C .get_version (C .int (fd )) != COMPATIBLE_VERSION {
45- return nil , ErrIncompatibleVersion
46+ return nil , errors . WithStack ( ErrIncompatibleVersion )
4647 }
4748
4849 return & Client {
@@ -61,11 +62,11 @@ func (c *Client) InjectIOEMDelay(devPath string, op int, pidNs uint, delay int64
6162 if len (devPath ) > 0 {
6263 info , err := os .Stat (devPath )
6364 if err != nil {
64- return 0 , err
65+ return 0 , errors . Wrapf ( err , "stat file: %s" , devPath )
6566 }
6667 stat , ok := info .Sys ().(* syscall.Stat_t )
6768 if ! ok {
68- return 0 , ErrFailToGetStat
69+ return 0 , errors . Wrap ( ErrFailToGetStat , "dev info is not a stat" )
6970 }
7071
7172 dev = C .uint32_t (stat .Rdev )
@@ -76,7 +77,7 @@ func (c *Client) InjectIOEMDelay(devPath string, op int, pidNs uint, delay int64
7677
7778 id := C .add_injection (C .int (c .fd ), 0 , unsafe .Pointer (& ioem_injection ), 0 , unsafe .Pointer (& delay_arg ))
7879 if id < 0 {
79- return 0 , syscall .Errno (- id )
80+ return 0 , errors . Wrap ( syscall .Errno (- id ), "add injection" )
8081 }
8182
8283 return int (id ), nil
@@ -85,7 +86,7 @@ func (c *Client) InjectIOEMDelay(devPath string, op int, pidNs uint, delay int64
8586func (c * Client ) Recover (id int ) error {
8687 err := C .del_injection (C .int (c .fd ), C .int (id ))
8788 if err != 0 {
88- return syscall .Errno (err )
89+ return errors . Wrap ( syscall .Errno (err ), "recover injection" )
8990 }
9091
9192 return nil
0 commit comments