Skip to content

Commit d8de1a7

Browse files
committed
*: stop using pkg/errors
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent 8806422 commit d8de1a7

13 files changed

Lines changed: 109 additions & 104 deletions

File tree

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ require (
1515
github.com/mrunalp/fileutils v0.5.0
1616
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
1717
github.com/opencontainers/selinux v1.8.2
18-
github.com/pkg/errors v0.9.1
1918
github.com/seccomp/libseccomp-golang v0.9.1
2019
github.com/sirupsen/logrus v1.8.1
2120
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635

libcontainer/cgroups/systemd/common.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,10 @@ func systemdVersionAtoi(verStr string) (int, error) {
436436
return 0, fmt.Errorf("can't parse version %s: incorrect number of matches %v", verStr, matches)
437437
}
438438
ver, err := strconv.Atoi(matches[1])
439-
return ver, fmt.Errorf("can't parse version: %w", err)
439+
if err != nil {
440+
return -1, fmt.Errorf("can't parse version: %w", err)
441+
}
442+
return ver, nil
440443
}
441444

442445
func addCpuQuota(cm *dbusConnManager, properties *[]systemdDbus.Property, quota int64, period uint64) {

libcontainer/configs/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
"os/exec"
88
"time"
99

10+
"github.com/sirupsen/logrus"
11+
1012
"github.com/opencontainers/runc/libcontainer/devices"
1113
"github.com/opencontainers/runtime-spec/specs-go"
12-
"github.com/pkg/errors"
13-
"github.com/sirupsen/logrus"
1414
)
1515

1616
type Rlimit struct {
@@ -262,7 +262,7 @@ type Capabilities struct {
262262
func (hooks HookList) RunHooks(state *specs.State) error {
263263
for i, h := range hooks {
264264
if err := h.Run(state); err != nil {
265-
return errors.Wrapf(err, "Running hook #%d:", i)
265+
return fmt.Errorf("error running hook #%d: %w", i, err)
266266
}
267267
}
268268

libcontainer/container_linux.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,20 @@ import (
1919
"sync"
2020
"time"
2121

22-
securejoin "github.com/cyphar/filepath-securejoin"
23-
"github.com/opencontainers/runc/libcontainer/cgroups"
24-
"github.com/opencontainers/runc/libcontainer/configs"
25-
"github.com/opencontainers/runc/libcontainer/intelrdt"
26-
"github.com/opencontainers/runc/libcontainer/system"
27-
"github.com/opencontainers/runc/libcontainer/utils"
28-
"github.com/opencontainers/runtime-spec/specs-go"
29-
3022
"github.com/checkpoint-restore/go-criu/v5"
3123
criurpc "github.com/checkpoint-restore/go-criu/v5/rpc"
32-
errorsf "github.com/pkg/errors"
24+
securejoin "github.com/cyphar/filepath-securejoin"
25+
"github.com/opencontainers/runtime-spec/specs-go"
3326
"github.com/sirupsen/logrus"
3427
"github.com/vishvananda/netlink/nl"
3528
"golang.org/x/sys/unix"
3629
"google.golang.org/protobuf/proto"
30+
31+
"github.com/opencontainers/runc/libcontainer/cgroups"
32+
"github.com/opencontainers/runc/libcontainer/configs"
33+
"github.com/opencontainers/runc/libcontainer/intelrdt"
34+
"github.com/opencontainers/runc/libcontainer/system"
35+
"github.com/opencontainers/runc/libcontainer/utils"
3736
)
3837

3938
const stdioFdCount = 3
@@ -390,7 +389,7 @@ func (c *linuxContainer) start(process *Process) (retErr error) {
390389

391390
if err := c.config.Hooks[configs.Poststart].RunHooks(s); err != nil {
392391
if err := ignoreTerminateErrors(parent.terminate()); err != nil {
393-
logrus.Warn(errorsf.Wrapf(err, "Running Poststart hook"))
392+
logrus.Warn(fmt.Errorf("error running poststart hook: %w", err))
394393
}
395394
return err
396395
}
@@ -1283,7 +1282,7 @@ func (c *linuxContainer) prepareCriuRestoreMounts(mounts []*configs.Mount) error
12831282
if m.Device == "bind" {
12841283
if err := utils.WithProcfd(c.config.Rootfs, m.Destination, func(procfd string) error {
12851284
if err := unix.Mount(m.Source, procfd, "", unix.MS_BIND|unix.MS_REC, ""); err != nil {
1286-
return errorsf.Wrapf(err, "unable to bind mount %q to %q (through %q)", m.Source, m.Destination, procfd)
1285+
return fmt.Errorf("unable to bind mount %q to %q (through %q): %w", m.Source, m.Destination, procfd, err)
12871286
}
12881287
return nil
12891288
}); err != nil {

libcontainer/factory_linux.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package libcontainer
44

55
import (
66
"encoding/json"
7+
"errors"
78
"fmt"
89
"os"
910
"path/filepath"
@@ -13,6 +14,8 @@ import (
1314

1415
securejoin "github.com/cyphar/filepath-securejoin"
1516
"github.com/moby/sys/mountinfo"
17+
"golang.org/x/sys/unix"
18+
1619
"github.com/opencontainers/runc/libcontainer/cgroups"
1720
"github.com/opencontainers/runc/libcontainer/cgroups/fs"
1821
"github.com/opencontainers/runc/libcontainer/cgroups/fs2"
@@ -21,9 +24,6 @@ import (
2124
"github.com/opencontainers/runc/libcontainer/configs/validate"
2225
"github.com/opencontainers/runc/libcontainer/intelrdt"
2326
"github.com/opencontainers/runc/libcontainer/utils"
24-
"github.com/pkg/errors"
25-
26-
"golang.org/x/sys/unix"
2727
)
2828

2929
const (
@@ -59,13 +59,13 @@ func getUnifiedPath(paths map[string]string) string {
5959
if path == "" {
6060
path = v
6161
} else if v != path {
62-
panic(errors.Errorf("expected %q path to be unified path %q, got %q", k, path, v))
62+
panic(fmt.Errorf("expected %q path to be unified path %q, got %q", k, path, v))
6363
}
6464
}
6565
// can be empty
6666
if path != "" {
6767
if filepath.Clean(path) != path || !filepath.IsAbs(path) {
68-
panic(errors.Errorf("invalid dir path %q", path))
68+
panic(fmt.Errorf("invalid dir path %q", path))
6969
}
7070
}
7171

libcontainer/init_linux.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package libcontainer
55
import (
66
"bytes"
77
"encoding/json"
8+
"errors"
89
"fmt"
910
"io"
1011
"io/ioutil"
@@ -14,17 +15,17 @@ import (
1415
"unsafe"
1516

1617
"github.com/containerd/console"
18+
"github.com/opencontainers/runtime-spec/specs-go"
19+
"github.com/sirupsen/logrus"
20+
"github.com/vishvananda/netlink"
21+
"golang.org/x/sys/unix"
22+
1723
"github.com/opencontainers/runc/libcontainer/capabilities"
1824
"github.com/opencontainers/runc/libcontainer/cgroups"
1925
"github.com/opencontainers/runc/libcontainer/configs"
2026
"github.com/opencontainers/runc/libcontainer/system"
2127
"github.com/opencontainers/runc/libcontainer/user"
2228
"github.com/opencontainers/runc/libcontainer/utils"
23-
"github.com/opencontainers/runtime-spec/specs-go"
24-
"github.com/pkg/errors"
25-
"github.com/sirupsen/logrus"
26-
"github.com/vishvananda/netlink"
27-
"golang.org/x/sys/unix"
2829
)
2930

3031
type initType string
@@ -139,7 +140,7 @@ func finalizeNamespace(config *initConfig) error {
139140
// inherited are marked close-on-exec so they stay out of the
140141
// container
141142
if err := utils.CloseExecFrom(config.PassedFilesCount + 3); err != nil {
142-
return errors.Wrap(err, "close exec fds")
143+
return fmt.Errorf("error closing exec fds: %w", err)
143144
}
144145

145146
// we only do chdir if it's specified
@@ -174,14 +175,14 @@ func finalizeNamespace(config *initConfig) error {
174175
}
175176
// drop capabilities in bounding set before changing user
176177
if err := w.ApplyBoundingSet(); err != nil {
177-
return errors.Wrap(err, "apply bounding set")
178+
return fmt.Errorf("unable to apply bounding set: %w", err)
178179
}
179180
// preserve existing capabilities while we change users
180181
if err := system.SetKeepCaps(); err != nil {
181-
return errors.Wrap(err, "set keep caps")
182+
return fmt.Errorf("unable to set keep caps: %w", err)
182183
}
183184
if err := setupUser(config); err != nil {
184-
return errors.Wrap(err, "setup user")
185+
return fmt.Errorf("unable to setup user: %w", err)
185186
}
186187
// Change working directory AFTER the user has been set up, if we haven't done it yet.
187188
if doChdir {
@@ -190,10 +191,10 @@ func finalizeNamespace(config *initConfig) error {
190191
}
191192
}
192193
if err := system.ClearKeepCaps(); err != nil {
193-
return errors.Wrap(err, "clear keep caps")
194+
return fmt.Errorf("unable to clear keep caps: %w", err)
194195
}
195196
if err := w.ApplyCaps(); err != nil {
196-
return errors.Wrap(err, "apply caps")
197+
return fmt.Errorf("unable to apply caps: %w", err)
197198
}
198199
return nil
199200
}

libcontainer/logs/logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package logs
33
import (
44
"bufio"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"io"
89
"os"
910
"sync"
1011

11-
"github.com/pkg/errors"
1212
"github.com/sirupsen/logrus"
1313
)
1414

libcontainer/notify_linux_v2.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@
33
package libcontainer
44

55
import (
6+
"fmt"
67
"path/filepath"
78
"unsafe"
89

910
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
10-
"github.com/pkg/errors"
1111
"github.com/sirupsen/logrus"
1212
"golang.org/x/sys/unix"
1313
)
1414

1515
func registerMemoryEventV2(cgDir, evName, cgEvName string) (<-chan struct{}, error) {
1616
fd, err := unix.InotifyInit()
1717
if err != nil {
18-
return nil, errors.Wrap(err, "unable to init inotify")
18+
return nil, fmt.Errorf("unable to init inotify: %w", err)
1919
}
2020
// watching oom kill
2121
evFd, err := unix.InotifyAddWatch(fd, filepath.Join(cgDir, evName), unix.IN_MODIFY)
2222
if err != nil {
2323
unix.Close(fd)
24-
return nil, errors.Wrap(err, "unable to add inotify watch")
24+
return nil, fmt.Errorf("unable to add inotify watch: %w", err)
2525
}
2626
// Because no `unix.IN_DELETE|unix.IN_DELETE_SELF` event for cgroup file system, so watching all process exited
2727
cgFd, err := unix.InotifyAddWatch(fd, filepath.Join(cgDir, cgEvName), unix.IN_MODIFY)
2828
if err != nil {
2929
unix.Close(fd)
30-
return nil, errors.Wrap(err, "unable to add inotify watch")
30+
return nil, fmt.Errorf("unable to add inotify watch: %w", err)
3131
}
3232
ch := make(chan struct{})
3333
go func() {

0 commit comments

Comments
 (0)