Skip to content

Commit 9e98ea7

Browse files
Merge pull request #555 from cfergeau/no-wrap
Stop using github.com/pkg/errors
2 parents 1568bb9 + 3e60be7 commit 9e98ea7

File tree

14 files changed

+60
-64
lines changed

14 files changed

+60
-64
lines changed

cmd/gvproxy/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"errors"
45
"flag"
56
"fmt"
67
"net"
@@ -12,7 +13,6 @@ import (
1213
"strings"
1314

1415
"github.com/containers/gvisor-tap-vsock/pkg/types"
15-
"github.com/pkg/errors"
1616
log "github.com/sirupsen/logrus"
1717
yaml "gopkg.in/yaml.v3"
1818
)
@@ -254,16 +254,16 @@ func GvproxyConfigure(config *GvproxyConfig, args *GvproxyArgs, version string)
254254
if config.Interfaces.Qemu != "" {
255255
uri, err := url.Parse(config.Interfaces.Qemu)
256256
if err != nil || uri == nil {
257-
return config, errors.Wrapf(err, "invalid value for qemu listen address")
257+
return config, fmt.Errorf("invalid value for qemu listen address: %w", err)
258258
}
259259
if _, err := os.Stat(uri.Path); err == nil && uri.Scheme == "unix" {
260-
return config, errors.Errorf("%q already exists", uri.Path)
260+
return config, fmt.Errorf("%q already exists", uri.Path)
261261
}
262262
}
263263
if config.Interfaces.Bess != "" {
264264
uri, err := url.Parse(config.Interfaces.Bess)
265265
if err != nil || uri == nil {
266-
return config, errors.Wrapf(err, "invalid value for bess listen address")
266+
return config, fmt.Errorf("invalid value for bess listen address: %w", err)
267267
}
268268
if uri.Scheme != "unixpacket" {
269269
return config, errors.New("bess listen address must be unixpacket:// address")
@@ -275,13 +275,13 @@ func GvproxyConfigure(config *GvproxyConfig, args *GvproxyArgs, version string)
275275
if config.Interfaces.Vfkit != "" {
276276
uri, err := url.Parse(config.Interfaces.Vfkit)
277277
if err != nil || uri == nil {
278-
return config, errors.Wrapf(err, "invalid value for vfkit listen address")
278+
return config, fmt.Errorf("invalid value for vfkit listen address: %w", err)
279279
}
280280
if uri.Scheme != "unixgram" {
281281
return config, errors.New("vfkit listen address must be unixgram:// address")
282282
}
283283
if _, err := os.Stat(uri.Path); err == nil {
284-
return config, errors.Errorf("%q already exists", uri.Path)
284+
return config, fmt.Errorf("%q already exists", uri.Path)
285285
}
286286
}
287287

@@ -381,7 +381,7 @@ func GvproxyConfigure(config *GvproxyConfig, args *GvproxyArgs, version string)
381381
for _, v := range config.Forwards {
382382
_, err := os.Stat(v.Identity)
383383
if err != nil {
384-
return config, errors.Wrapf(err, "Identity file \"%s\" can't be loaded", v.Identity)
384+
return config, fmt.Errorf("identity file %q can't be loaded: %w", v.Identity, err)
385385
}
386386
}
387387

cmd/gvproxy/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ forwards:
465465
user: ???
466466
identity: ???
467467
`,
468-
ErrorPrefix: "Identity file",
468+
ErrorPrefix: "identity file",
469469
},
470470
{
471471
CaseName: "debug check #1",

cmd/gvproxy/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"bufio"
55
"context"
6+
"errors"
67
"fmt"
78
"net"
89
"net/http"
@@ -22,7 +23,6 @@ import (
2223
"github.com/containers/gvisor-tap-vsock/pkg/virtualnetwork"
2324
"github.com/containers/winquit/pkg/winquit"
2425
humanize "github.com/dustin/go-humanize"
25-
"github.com/pkg/errors"
2626
log "github.com/sirupsen/logrus"
2727
"golang.org/x/sync/errgroup"
2828
)
@@ -130,7 +130,7 @@ func run(ctx context.Context, g *errgroup.Group, config *GvproxyConfig) error {
130130
log.Infof("listening %s", endpoint)
131131
ln, err := transport.Listen(endpoint)
132132
if err != nil {
133-
return errors.Wrap(err, "cannot listen")
133+
return fmt.Errorf("cannot listen: %w", err)
134134
}
135135
httpServe(ctx, g, ln, withProfiler(vn))
136136
}
@@ -139,7 +139,7 @@ func run(ctx context.Context, g *errgroup.Group, config *GvproxyConfig) error {
139139
log.Infof("enabling services API. Listening %s", config.Services)
140140
ln, err := transport.Listen(config.Services)
141141
if err != nil {
142-
return errors.Wrap(err, "cannot listen")
142+
return fmt.Errorf("cannot listen: %w", err)
143143
}
144144
httpServe(ctx, g, ln, vn.ServicesMux())
145145
}
@@ -172,7 +172,7 @@ func run(ctx context.Context, g *errgroup.Group, config *GvproxyConfig) error {
172172
if config.Interfaces.VPNKit != "" {
173173
vpnkitListener, err := transport.Listen(config.Interfaces.VPNKit)
174174
if err != nil {
175-
return errors.Wrap(err, "vpnkit listen error")
175+
return fmt.Errorf("vpnkit listen error: %w", err)
176176
}
177177
g.Go(func() error {
178178
vpnloop:
@@ -199,7 +199,7 @@ func run(ctx context.Context, g *errgroup.Group, config *GvproxyConfig) error {
199199
if config.Interfaces.Qemu != "" {
200200
qemuListener, err := transport.Listen(config.Interfaces.Qemu)
201201
if err != nil {
202-
return errors.Wrap(err, "qemu listen error")
202+
return fmt.Errorf("qemu listen error: %w", err)
203203
}
204204

205205
g.Go(func() error {
@@ -213,7 +213,7 @@ func run(ctx context.Context, g *errgroup.Group, config *GvproxyConfig) error {
213213
g.Go(func() error {
214214
conn, err := qemuListener.Accept()
215215
if err != nil {
216-
return errors.Wrap(err, "qemu accept error")
216+
return fmt.Errorf("qemu accept error: %w", err)
217217
}
218218
return vn.AcceptQemu(ctx, conn)
219219
})
@@ -222,7 +222,7 @@ func run(ctx context.Context, g *errgroup.Group, config *GvproxyConfig) error {
222222
if config.Interfaces.Bess != "" {
223223
bessListener, err := transport.Listen(config.Interfaces.Bess)
224224
if err != nil {
225-
return errors.Wrap(err, "bess listen error")
225+
return fmt.Errorf("bess listen error: %w", err)
226226
}
227227

228228
g.Go(func() error {
@@ -236,7 +236,7 @@ func run(ctx context.Context, g *errgroup.Group, config *GvproxyConfig) error {
236236
g.Go(func() error {
237237
conn, err := bessListener.Accept()
238238
if err != nil {
239-
return errors.Wrap(err, "bess accept error")
239+
return fmt.Errorf("bess accept error: %w", err)
240240
}
241241
return vn.AcceptBess(ctx, conn)
242242
})
@@ -245,7 +245,7 @@ func run(ctx context.Context, g *errgroup.Group, config *GvproxyConfig) error {
245245
if config.Interfaces.Vfkit != "" {
246246
conn, err := transport.ListenUnixgram(config.Interfaces.Vfkit)
247247
if err != nil {
248-
return errors.Wrap(err, "vfkit listen error")
248+
return fmt.Errorf("vfkit listen error: %w", err)
249249
}
250250

251251
g.Go(func() error {
@@ -260,7 +260,7 @@ func run(ctx context.Context, g *errgroup.Group, config *GvproxyConfig) error {
260260
g.Go(func() error {
261261
vfkitConn, err := transport.AcceptVfkit(conn)
262262
if err != nil {
263-
return errors.Wrap(err, "vfkit accept error")
263+
return fmt.Errorf("vfkit accept error: %w", err)
264264
}
265265
return vn.AcceptVfkit(ctx, vfkitConn)
266266
})

cmd/ssh-over-vsock/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/containers/gvisor-tap-vsock/pkg/transport"
1010
"github.com/containers/gvisor-tap-vsock/pkg/types"
11-
"github.com/pkg/errors"
1211
"github.com/sirupsen/logrus"
1312
)
1413

@@ -43,7 +42,7 @@ func main() {
4342
func run() error {
4443
conn, err := net.Dial("unix", endpoint)
4544
if err != nil {
46-
return errors.Wrap(err, "cannot connect to host")
45+
return fmt.Errorf("cannot connect to host: %w", err)
4746
}
4847
defer conn.Close()
4948

cmd/vm/main_linux.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/containers/gvisor-tap-vsock/pkg/types"
1919
"github.com/google/gopacket"
2020
"github.com/google/gopacket/layers"
21-
"github.com/pkg/errors"
2221
log "github.com/sirupsen/logrus"
2322
"github.com/songgao/packets/ethernet"
2423
"github.com/songgao/water"
@@ -76,7 +75,7 @@ func run() error {
7675
log.Infof("Dialing to %s…", endpoint)
7776
conn, path, err := transport.Dial(endpoint)
7877
if err != nil {
79-
return errors.Wrap(err, "cannot connect to host")
78+
return fmt.Errorf("cannot connect to host: %w", err)
8079
}
8180
defer conn.Close()
8281

@@ -99,14 +98,14 @@ func run() error {
9998
},
10099
})
101100
if err != nil {
102-
return errors.Wrap(err, "cannot create tap device")
101+
return fmt.Errorf("cannot create tap device: %w", err)
103102
}
104103
defer tap.Close()
105104

106105
if !tapPreexists {
107106
log.Infof("Enabling tap device %s", iface)
108107
if err := linkUp(); err != nil {
109-
return errors.Wrap(err, "cannot set mac address")
108+
return fmt.Errorf("cannot set mac address: %w", err)
110109
}
111110
}
112111

@@ -118,7 +117,7 @@ func run() error {
118117
if !tapPreexists {
119118
go func() {
120119
if err := dhcp(); err != nil {
121-
errCh <- errors.Wrap(err, "dhcp error")
120+
errCh <- fmt.Errorf("dhcp error: %w", err)
122121
}
123122
}()
124123
}
@@ -164,7 +163,7 @@ func rx(conn net.Conn, tap *water.Interface, errCh chan error, mtu int) {
164163
frame.Resize(mtu)
165164
n, err := tap.Read([]byte(frame))
166165
if err != nil {
167-
errCh <- errors.Wrap(err, "cannot read packet from tap")
166+
errCh <- fmt.Errorf("cannot read packet from tap: %w", err)
168167
return
169168
}
170169
frame = frame[:n]
@@ -180,7 +179,7 @@ func rx(conn net.Conn, tap *water.Interface, errCh chan error, mtu int) {
180179
}
181180
binary.LittleEndian.PutUint16(size, uint16(n))
182181
if _, err := conn.Write(append(size, frame...)); err != nil {
183-
errCh <- errors.Wrap(err, "cannot write size and packet to socket")
182+
errCh <- fmt.Errorf("cannot write size and packet to socket: %w", err)
184183
return
185184
}
186185
}
@@ -193,7 +192,7 @@ func tx(conn net.Conn, tap *water.Interface, errCh chan error, mtu int) {
193192
for {
194193
n, err := io.ReadFull(conn, sizeBuf)
195194
if err != nil {
196-
errCh <- errors.Wrap(err, "cannot read size from socket")
195+
errCh <- fmt.Errorf("cannot read size from socket: %w", err)
197196
return
198197
}
199198
if n != 2 {
@@ -204,7 +203,7 @@ func tx(conn net.Conn, tap *water.Interface, errCh chan error, mtu int) {
204203

205204
n, err = io.ReadFull(conn, buf[:size])
206205
if err != nil {
207-
errCh <- errors.Wrap(err, "cannot read payload from socket")
206+
errCh <- fmt.Errorf("cannot read payload from socket: %w", err)
208207
return
209208
}
210209
if n == 0 || n != size {
@@ -218,7 +217,7 @@ func tx(conn net.Conn, tap *water.Interface, errCh chan error, mtu int) {
218217
}
219218

220219
if _, err := tap.Write(buf[:size]); err != nil {
221-
errCh <- errors.Wrap(err, "cannot write packet to tap")
220+
errCh <- fmt.Errorf("cannot write packet to tap: %w", err)
222221
return
223222
}
224223
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ require (
1616
github.com/onsi/ginkgo v1.16.5
1717
github.com/onsi/gomega v1.38.2
1818
github.com/opencontainers/go-digest v1.0.0
19-
github.com/pkg/errors v0.9.1
2019
github.com/sirupsen/logrus v1.9.3
2120
github.com/songgao/packets v0.0.0-20160404182456-549a10cd4091
2221
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
@@ -38,6 +37,7 @@ require (
3837
github.com/mdlayher/socket v0.4.1 // indirect
3938
github.com/nxadm/tail v1.4.8 // indirect
4039
github.com/pierrec/lz4/v4 v4.1.14 // indirect
40+
github.com/pkg/errors v0.9.1 // indirect
4141
github.com/pmezard/go-difflib v1.0.0 // indirect
4242
github.com/u-root/uio v0.0.0-20240224005618-d2acac8f3701 // indirect
4343
github.com/vishvananda/netns v0.0.5 // indirect

pkg/sshclient/bastion.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sshclient
33
import (
44
"bufio"
55
"context"
6+
"errors"
67
"fmt"
78
"net"
89
"net/url"
@@ -13,7 +14,6 @@ import (
1314
"sync"
1415
"time"
1516

16-
"github.com/pkg/errors"
1717
"github.com/sirupsen/logrus"
1818
"golang.org/x/crypto/ssh"
1919
"golang.org/x/crypto/ssh/knownhosts"
@@ -90,7 +90,7 @@ func CreateBastion(_url *url.URL, passPhrase string, identity string, initial ne
9090
if len(identity) > 0 {
9191
s, err := PublicKey(identity, []byte(passPhrase))
9292
if err != nil {
93-
return nil, errors.Wrapf(err, "failed to parse identity %q", identity)
93+
return nil, fmt.Errorf("failed to parse identity %q: %w", identity, err)
9494
}
9595
authMethods = append(authMethods, ssh.PublicKeys(s))
9696
}
@@ -100,7 +100,7 @@ func CreateBastion(_url *url.URL, passPhrase string, identity string, initial ne
100100
}
101101

102102
if len(authMethods) == 0 {
103-
return nil, errors.New("No available auth methods")
103+
return nil, errors.New("no available auth methods")
104104
}
105105

106106
port := _url.Port()
@@ -167,7 +167,7 @@ func (bastion *Bastion) reconnect(ctx context.Context, conn net.Conn) error {
167167
conn, err = bastion.connect(ctx, bastion)
168168
}
169169
if err != nil {
170-
return errors.Wrapf(err, "Connection to bastion host (%s) failed", bastion.Host)
170+
return fmt.Errorf("connection to bastion host (%s) failed: %w", bastion.Host, err)
171171
}
172172
addr := net.JoinHostPort(bastion.Host, bastion.Port)
173173
c, chans, reqs, err := ssh.NewClientConn(conn, addr, bastion.Config)

pkg/sshclient/npipe_windows.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strings"
99

1010
winio "github.com/Microsoft/go-winio"
11-
"github.com/pkg/errors"
1211
"github.com/sirupsen/logrus"
1312
)
1413

@@ -34,7 +33,7 @@ func ListenNpipe(socketURI *url.URL) (net.Listener, error) {
3433

3534
listener, err := winio.ListenPipe(path, &config)
3635
if err != nil {
37-
return listener, errors.Wrapf(err, "Error listening on socket: %s", socketURI)
36+
return listener, fmt.Errorf("error listening on socket: %s: %w", socketURI, err)
3837
}
3938

4039
logrus.Info("Listening on: " + path)

0 commit comments

Comments
 (0)