Skip to content

Commit 1697e73

Browse files
authored
Merge pull request #71 from AkihiroSuda/remove-pkg-errors
remove direct dependency on github.com/pkg/errors
2 parents 548a5e1 + b6c559f commit 1697e73

File tree

6 files changed

+14
-18
lines changed

6 files changed

+14
-18
lines changed

cni.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
cnilibrary "github.com/containernetworking/cni/libcni"
2626
"github.com/containernetworking/cni/pkg/types"
2727
types100 "github.com/containernetworking/cni/pkg/types/100"
28-
"github.com/pkg/errors"
2928
)
3029

3130
type CNI interface {
@@ -115,7 +114,7 @@ func (c *libcni) Load(opts ...Opt) error {
115114

116115
for _, o := range opts {
117116
if err = o(c); err != nil {
118-
return errors.Wrapf(ErrLoad, fmt.Sprintf("cni config load failed: %v", err))
117+
return fmt.Errorf("cni config load failed: %v: %w", err, ErrLoad)
119118
}
120119
}
121120
return nil

errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package cni
1818

1919
import (
20-
"github.com/pkg/errors"
20+
"errors"
2121
)
2222

2323
var (

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/containerd/go-cni
33
require (
44
github.com/containernetworking/cni v1.0.0
55
github.com/davecgh/go-spew v1.1.1 // indirect
6-
github.com/pkg/errors v0.9.1
76
github.com/stretchr/testify v1.6.1
87
)
98

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ github.com/onsi/ginkgo v1.13.0/go.mod h1:+REjRxOmWfHCjfv9TTWB1jD1Frx4XydAD3zm1ls
2828
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
2929
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
3030
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
31-
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
32-
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
3331
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3432
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3533
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=

opts.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
package cni
1818

1919
import (
20+
"fmt"
2021
"sort"
2122
"strings"
2223

2324
cnilibrary "github.com/containernetworking/cni/libcni"
24-
"github.com/pkg/errors"
2525
)
2626

2727
// Opt sets options for a CNI instance
@@ -204,9 +204,9 @@ func loadFromConfDir(c *libcni, max int) error {
204204
files, err := cnilibrary.ConfFiles(c.pluginConfDir, []string{".conf", ".conflist", ".json"})
205205
switch {
206206
case err != nil:
207-
return errors.Wrapf(ErrRead, "failed to read config file: %v", err)
207+
return fmt.Errorf("failed to read config file: %v: %w", err, ErrRead)
208208
case len(files) == 0:
209-
return errors.Wrapf(ErrCNINotInitialized, "no network config found in %s", c.pluginConfDir)
209+
return fmt.Errorf("no network config found in %s: %w", c.pluginConfDir, ErrCNINotInitialized)
210210
}
211211

212212
// files contains the network config files associated with cni network.
@@ -224,26 +224,26 @@ func loadFromConfDir(c *libcni, max int) error {
224224
if strings.HasSuffix(confFile, ".conflist") {
225225
confList, err = cnilibrary.ConfListFromFile(confFile)
226226
if err != nil {
227-
return errors.Wrapf(ErrInvalidConfig, "failed to load CNI config list file %s: %v", confFile, err)
227+
return fmt.Errorf("failed to load CNI config list file %s: %v: %w", confFile, err, ErrInvalidConfig)
228228
}
229229
} else {
230230
conf, err := cnilibrary.ConfFromFile(confFile)
231231
if err != nil {
232-
return errors.Wrapf(ErrInvalidConfig, "failed to load CNI config file %s: %v", confFile, err)
232+
return fmt.Errorf("failed to load CNI config file %s: %v: %w", confFile, err, ErrInvalidConfig)
233233
}
234234
// Ensure the config has a "type" so we know what plugin to run.
235235
// Also catches the case where somebody put a conflist into a conf file.
236236
if conf.Network.Type == "" {
237-
return errors.Wrapf(ErrInvalidConfig, "network type not found in %s", confFile)
237+
return fmt.Errorf("network type not found in %s: %w", confFile, ErrInvalidConfig)
238238
}
239239

240240
confList, err = cnilibrary.ConfListFromConf(conf)
241241
if err != nil {
242-
return errors.Wrapf(ErrInvalidConfig, "failed to convert CNI config file %s to CNI config list: %v", confFile, err)
242+
return fmt.Errorf("failed to convert CNI config file %s to CNI config list: %v: %w", confFile, err, ErrInvalidConfig)
243243
}
244244
}
245245
if len(confList.Plugins) == 0 {
246-
return errors.Wrapf(ErrInvalidConfig, "CNI config list in config file %s has no networks, skipping", confFile)
246+
return fmt.Errorf("CNI config list in config file %s has no networks, skipping: %w", confFile, ErrInvalidConfig)
247247

248248
}
249249
networks = append(networks, &Network{
@@ -257,7 +257,7 @@ func loadFromConfDir(c *libcni, max int) error {
257257
}
258258
}
259259
if len(networks) == 0 {
260-
return errors.Wrapf(ErrCNINotInitialized, "no valid networks found in %s", c.pluginDirs)
260+
return fmt.Errorf("no valid networks found in %s: %w", c.pluginDirs, ErrCNINotInitialized)
261261
}
262262
c.networks = append(c.networks, networks...)
263263
return nil

result.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
package cni
1818

1919
import (
20+
"fmt"
2021
"net"
2122

2223
"github.com/containernetworking/cni/pkg/types"
2324
types100 "github.com/containernetworking/cni/pkg/types/100"
24-
"github.com/pkg/errors"
2525
)
2626

2727
type IPConfig struct {
@@ -87,7 +87,7 @@ func (c *libcni) createResult(results []*types100.Result) (*Result, error) {
8787
// interfaces
8888
for _, ipConf := range result.IPs {
8989
if err := validateInterfaceConfig(ipConf, len(result.Interfaces)); err != nil {
90-
return nil, errors.Wrapf(ErrInvalidResult, "invalid interface config: %v", err)
90+
return nil, fmt.Errorf("invalid interface config: %v: %w", err, ErrInvalidResult)
9191
}
9292
name := c.getInterfaceName(result.Interfaces, ipConf)
9393
r.Interfaces[name].IPConfigs = append(r.Interfaces[name].IPConfigs,
@@ -97,7 +97,7 @@ func (c *libcni) createResult(results []*types100.Result) (*Result, error) {
9797
r.Routes = append(r.Routes, result.Routes...)
9898
}
9999
if _, ok := r.Interfaces[defaultInterface(c.prefix)]; !ok {
100-
return nil, errors.Wrapf(ErrNotFound, "default network not found for: %s", defaultInterface(c.prefix))
100+
return nil, fmt.Errorf("default network not found for: %s: %w", defaultInterface(c.prefix), ErrNotFound)
101101
}
102102
return r, nil
103103
}

0 commit comments

Comments
 (0)