Skip to content

Commit 2e2a862

Browse files
committed
all: drop x/xerrors in favor of fmt+errors
1 parent 361b05f commit 2e2a862

30 files changed

Lines changed: 287 additions & 299 deletions

conn.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ package zmq4
77
import (
88
"bytes"
99
"encoding/binary"
10+
"errors"
11+
"fmt"
1012
"io"
1113
"net"
1214
"strings"
1315
"sync"
1416
"sync/atomic"
15-
16-
"golang.org/x/xerrors"
1717
)
1818

19-
var ErrClosedConn = xerrors.New("zmq4: read/write on closed connection")
19+
var ErrClosedConn = errors.New("zmq4: read/write on closed connection")
2020

2121
// Conn implements the ZeroMQ Message Transport Protocol as defined
2222
// in https://rfc.zeromq.org/spec:23/ZMTP/.
@@ -66,11 +66,11 @@ func (c *Conn) Write(p []byte) (int, error) {
6666
// Open performs a complete ZMTP handshake.
6767
func Open(rw net.Conn, sec Security, sockType SocketType, sockID SocketIdentity, server bool, onCloseErrorCB func(c *Conn)) (*Conn, error) {
6868
if rw == nil {
69-
return nil, xerrors.Errorf("zmq4: invalid nil read-writer")
69+
return nil, fmt.Errorf("zmq4: invalid nil read-writer")
7070
}
7171

7272
if sec == nil {
73-
return nil, xerrors.Errorf("zmq4: invalid nil security")
73+
return nil, fmt.Errorf("zmq4: invalid nil security")
7474
}
7575

7676
conn := &Conn{
@@ -89,7 +89,7 @@ func Open(rw net.Conn, sec Security, sockType SocketType, sockID SocketIdentity,
8989

9090
err := conn.init(sec)
9191
if err != nil {
92-
return nil, xerrors.Errorf("zmq4: could not initialize ZMTP connection: %w", err)
92+
return nil, fmt.Errorf("zmq4: could not initialize ZMTP connection: %w", err)
9393
}
9494

9595
return conn, nil
@@ -101,17 +101,17 @@ func (conn *Conn) init(sec Security) error {
101101

102102
err = conn.greet(conn.Server)
103103
if err != nil {
104-
return xerrors.Errorf("zmq4: could not exchange greetings: %w", err)
104+
return fmt.Errorf("zmq4: could not exchange greetings: %w", err)
105105
}
106106

107107
err = conn.sec.Handshake(conn, conn.Server)
108108
if err != nil {
109-
return xerrors.Errorf("zmq4: could not perform security handshake: %w", err)
109+
return fmt.Errorf("zmq4: could not perform security handshake: %w", err)
110110
}
111111

112112
peer := SocketType(conn.Peer.Meta[sysSockType])
113113
if !peer.IsCompatible(conn.typ) {
114-
return xerrors.Errorf("zmq4: peer=%q not compatible with %q", peer, conn.typ)
114+
return fmt.Errorf("zmq4: peer=%q not compatible with %q", peer, conn.typ)
115115
}
116116

117117
// FIXME(sbinet): if security mechanism does not define a client/server
@@ -136,14 +136,14 @@ func (conn *Conn) greet(server bool) error {
136136
err = send.write(conn.rw)
137137
if err != nil {
138138
conn.checkIO(err)
139-
return xerrors.Errorf("zmq4: could not send greeting: %w", err)
139+
return fmt.Errorf("zmq4: could not send greeting: %w", err)
140140
}
141141

142142
var recv greeting
143143
err = recv.read(conn.rw)
144144
if err != nil {
145145
conn.checkIO(err)
146-
return xerrors.Errorf("zmq4: could not recv greeting: %w", err)
146+
return fmt.Errorf("zmq4: could not recv greeting: %w", err)
147147
}
148148

149149
peerKind := asString(recv.Mechanism[:])
@@ -153,7 +153,7 @@ func (conn *Conn) greet(server bool) error {
153153

154154
conn.Peer.Server, err = asBool(recv.Server)
155155
if err != nil {
156-
return xerrors.Errorf("zmq4: could not get peer server flag: %w", err)
156+
return fmt.Errorf("zmq4: could not get peer server flag: %w", err)
157157
}
158158

159159
return nil
@@ -189,7 +189,7 @@ func (c *Conn) SendMsg(msg Msg) error {
189189
}
190190
err := c.send(false, frame, flag)
191191
if err != nil {
192-
return xerrors.Errorf("zmq4: error sending frame %d/%d: %w", i+1, nframes, err)
192+
return fmt.Errorf("zmq4: error sending frame %d/%d: %w", i+1, nframes, err)
193193
}
194194
}
195195
return nil
@@ -202,7 +202,7 @@ func (c *Conn) RecvMsg() (Msg, error) {
202202
}
203203
msg := c.read()
204204
if msg.err != nil {
205-
return msg, xerrors.Errorf("zmq4: could not read recv msg: %w", msg.err)
205+
return msg, fmt.Errorf("zmq4: could not read recv msg: %w", msg.err)
206206
}
207207

208208
if !msg.isCmd() {
@@ -211,19 +211,19 @@ func (c *Conn) RecvMsg() (Msg, error) {
211211

212212
switch len(msg.Frames) {
213213
case 0:
214-
msg.err = xerrors.Errorf("zmq4: empty command")
214+
msg.err = fmt.Errorf("zmq4: empty command")
215215
return msg, msg.err
216216
case 1:
217217
// ok
218218
default:
219-
msg.err = xerrors.Errorf("zmq4: invalid length command")
219+
msg.err = fmt.Errorf("zmq4: invalid length command")
220220
return msg, msg.err
221221
}
222222

223223
var cmd Cmd
224224
msg.err = cmd.unmarshalZMTP(msg.Frames[0])
225225
if msg.err != nil {
226-
return msg, xerrors.Errorf("zmq4: could not unmarshal ZMTP recv msg: %w", msg.err)
226+
return msg, fmt.Errorf("zmq4: could not unmarshal ZMTP recv msg: %w", msg.err)
227227
}
228228

229229
switch cmd.Name {
@@ -254,7 +254,7 @@ func (c *Conn) RecvCmd() (Cmd, error) {
254254

255255
msg := c.read()
256256
if msg.err != nil {
257-
return cmd, xerrors.Errorf("zmq4: could not read recv cmd: %w", msg.err)
257+
return cmd, fmt.Errorf("zmq4: could not read recv cmd: %w", msg.err)
258258
}
259259

260260
if !msg.isCmd() {
@@ -263,18 +263,18 @@ func (c *Conn) RecvCmd() (Cmd, error) {
263263

264264
switch len(msg.Frames) {
265265
case 0:
266-
msg.err = xerrors.Errorf("zmq4: empty command")
266+
msg.err = fmt.Errorf("zmq4: empty command")
267267
return cmd, msg.err
268268
case 1:
269269
// ok
270270
default:
271-
msg.err = xerrors.Errorf("zmq4: invalid length command")
271+
msg.err = fmt.Errorf("zmq4: invalid length command")
272272
return cmd, msg.err
273273
}
274274

275275
err := cmd.unmarshalZMTP(msg.Frames[0])
276276
if err != nil {
277-
return cmd, xerrors.Errorf("zmq4: could not unmarshal ZMTP recv cmd: %w", err)
277+
return cmd, fmt.Errorf("zmq4: could not unmarshal ZMTP recv cmd: %w", err)
278278
}
279279

280280
return cmd, nil
@@ -482,13 +482,13 @@ func (conn *Conn) checkIO(err error) {
482482
return
483483
}
484484

485-
if err == io.EOF || xerrors.Is(err, io.EOF) {
485+
if err == io.EOF || errors.Is(err, io.EOF) {
486486
conn.SetClosed()
487487
return
488488
}
489489

490490
var e net.Error
491-
if xerrors.As(err, &e); e != nil && !e.Timeout() {
491+
if errors.As(err, &e); e != nil && !e.Timeout() {
492492
conn.SetClosed()
493493
}
494494
}

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ go 1.13
55
require (
66
github.com/go-zeromq/goczmq/v4 v4.2.2
77
golang.org/x/sync v0.0.0-20190423024810-112230192c58
8-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
98
)

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@ github.com/go-zeromq/goczmq/v4 v4.2.2 h1:HAJN+i+3NW55ijMJJhk7oWxHKXgAuSBkoFfvr8b
22
github.com/go-zeromq/goczmq/v4 v4.2.2/go.mod h1:Sm/lxrfxP/Oxqs0tnHD6WAhwkWrx+S+1MRrKzcxoaYE=
33
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
44
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
5-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
6-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

internal/inproc/inproc.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
package inproc
1111

1212
import (
13+
"errors"
14+
"fmt"
1315
"net"
1416
"strings"
1517
"sync"
16-
17-
"golang.org/x/xerrors"
1818
)
1919

2020
var (
2121
mgr = context{db: make(map[string]*Listener)}
2222

23-
ErrClosed = xerrors.New("inproc: connection closed")
24-
ErrConnRefused = xerrors.New("inproc: connection refused")
23+
ErrClosed = errors.New("inproc: connection closed")
24+
ErrConnRefused = errors.New("inproc: connection refused")
2525
)
2626

2727
func init() {
@@ -96,7 +96,7 @@ func Listen(addr string) (*Listener, error) {
9696
_, dup := mgr.db[addr]
9797
if dup {
9898
mgr.mu.Unlock()
99-
return nil, xerrors.Errorf("inproc: address %q already in use", addr)
99+
return nil, fmt.Errorf("inproc: address %q already in use", addr)
100100
}
101101

102102
l := &Listener{

internal/inproc/inproc_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ package inproc
66

77
import (
88
"bytes"
9+
"fmt"
910
"io"
1011
"math/rand"
1112
"reflect"
1213
"testing"
1314

1415
"golang.org/x/sync/errgroup"
15-
"golang.org/x/xerrors"
1616
)
1717

1818
func TestBasicIO(t *testing.T) {
@@ -84,7 +84,7 @@ func TestRW(t *testing.T) {
8484
grp.Go(func() error {
8585
conn, err := lst.Accept()
8686
if err != nil {
87-
return xerrors.Errorf("could not accept connection: %w", err)
87+
return fmt.Errorf("could not accept connection: %w", err)
8888
}
8989
defer conn.Close()
9090

@@ -101,26 +101,26 @@ func TestRW(t *testing.T) {
101101
raw := make([]byte, len("HELLO"))
102102
_, err = io.ReadFull(conn, raw)
103103
if err != nil {
104-
return xerrors.Errorf("could not read request: %w", err)
104+
return fmt.Errorf("could not read request: %w", err)
105105
}
106106

107107
if got, want := raw, []byte("HELLO"); !reflect.DeepEqual(got, want) {
108-
return xerrors.Errorf("invalid request: got=%v, want=%v", got, want)
108+
return fmt.Errorf("invalid request: got=%v, want=%v", got, want)
109109
}
110110

111111
_, err = conn.Write([]byte("HELLO"))
112112
if err != nil {
113-
return xerrors.Errorf("could not write reply: %w", err)
113+
return fmt.Errorf("could not write reply: %w", err)
114114
}
115115

116116
raw = make([]byte, len("QUIT"))
117117
_, err = io.ReadFull(conn, raw)
118118
if err != nil {
119-
return xerrors.Errorf("could not read final request: %w", err)
119+
return fmt.Errorf("could not read final request: %w", err)
120120
}
121121

122122
if got, want := raw, []byte("QUIT"); !reflect.DeepEqual(got, want) {
123-
return xerrors.Errorf("invalid request: got=%v, want=%v", got, want)
123+
return fmt.Errorf("invalid request: got=%v, want=%v", got, want)
124124
}
125125

126126
return nil
@@ -129,7 +129,7 @@ func TestRW(t *testing.T) {
129129
grp.Go(func() error {
130130
conn, err := Dial("inproc://rw-srv")
131131
if err != nil {
132-
return xerrors.Errorf("could not dial server: %w", err)
132+
return fmt.Errorf("could not dial server: %w", err)
133133
}
134134
defer conn.Close()
135135

@@ -145,22 +145,22 @@ func TestRW(t *testing.T) {
145145

146146
_, err = conn.Write([]byte("HELLO"))
147147
if err != nil {
148-
return xerrors.Errorf("could not send request: %w", err)
148+
return fmt.Errorf("could not send request: %w", err)
149149
}
150150

151151
raw := make([]byte, len("HELLO"))
152152
_, err = io.ReadFull(conn, raw)
153153
if err != nil {
154-
return xerrors.Errorf("could not read reply: %w", err)
154+
return fmt.Errorf("could not read reply: %w", err)
155155
}
156156

157157
if got, want := raw, []byte("HELLO"); !reflect.DeepEqual(got, want) {
158-
return xerrors.Errorf("invalid reply: got=%v, want=%v", got, want)
158+
return fmt.Errorf("invalid reply: got=%v, want=%v", got, want)
159159
}
160160

161161
_, err = conn.Write([]byte("QUIT"))
162162
if err != nil {
163-
return xerrors.Errorf("could not write final request: %w", err)
163+
return fmt.Errorf("could not write final request: %w", err)
164164
}
165165

166166
return nil

protocol.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ package zmq4
77
import (
88
"bytes"
99
"encoding/binary"
10+
"errors"
11+
"fmt"
1012
"io"
1113
"strings"
12-
13-
"golang.org/x/xerrors"
1414
)
1515

1616
var (
17-
errGreeting = xerrors.New("zmq4: invalid greeting received")
18-
errSecMech = xerrors.New("zmq4: invalid security mechanism")
19-
errBadSec = xerrors.New("zmq4: invalid or unsupported security mechanism")
20-
ErrBadCmd = xerrors.New("zmq4: invalid command name")
21-
ErrBadFrame = xerrors.New("zmq4: invalid frame")
22-
errOverflow = xerrors.New("zmq4: overflow")
23-
errEmptyAppMDKey = xerrors.New("zmq4: empty application metadata key")
24-
errDupAppMDKey = xerrors.New("zmq4: duplicate application metadata key")
25-
errBoolCnv = xerrors.New("zmq4: invalid byte to bool conversion")
17+
errGreeting = errors.New("zmq4: invalid greeting received")
18+
errSecMech = errors.New("zmq4: invalid security mechanism")
19+
errBadSec = errors.New("zmq4: invalid or unsupported security mechanism")
20+
ErrBadCmd = errors.New("zmq4: invalid command name")
21+
ErrBadFrame = errors.New("zmq4: invalid frame")
22+
errOverflow = errors.New("zmq4: overflow")
23+
errEmptyAppMDKey = errors.New("zmq4: empty application metadata key")
24+
errDupAppMDKey = errors.New("zmq4: duplicate application metadata key")
25+
errBoolCnv = errors.New("zmq4: invalid byte to bool conversion")
2626
)
2727

2828
const (
@@ -95,21 +95,21 @@ func (g *greeting) read(r io.Reader) error {
9595
var data [zmtpMsgLen]byte
9696
_, err := io.ReadFull(r, data[:])
9797
if err != nil {
98-
return xerrors.Errorf("could not read ZMTP greeting: %w", err)
98+
return fmt.Errorf("could not read ZMTP greeting: %w", err)
9999
}
100100

101101
g.unmarshal(data[:])
102102

103103
if g.Sig.Header != sigHeader {
104-
return xerrors.Errorf("invalid ZMTP signature header: %w", errGreeting)
104+
return fmt.Errorf("invalid ZMTP signature header: %w", errGreeting)
105105
}
106106

107107
if g.Sig.Footer != sigFooter {
108-
return xerrors.Errorf("invalid ZMTP signature footer: %w", errGreeting)
108+
return fmt.Errorf("invalid ZMTP signature footer: %w", errGreeting)
109109
}
110110

111111
if !g.validate(defaultVersion) {
112-
return xerrors.Errorf(
112+
return fmt.Errorf(
113113
"invalid ZMTP version (got=%v, want=%v): %w",
114114
g.Version, defaultVersion, errGreeting,
115115
)

0 commit comments

Comments
 (0)