Skip to content

Commit de51da9

Browse files
committed
Remove github.com/pkg/errors
1 parent 4dd2a4a commit de51da9

37 files changed

+56
-756
lines changed

cmd/root.go

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

33
import (
4+
"errors"
45
"fmt"
56
"os"
67
"os/signal"
@@ -9,7 +10,6 @@ import (
910

1011
"github.com/grepplabs/mqtt-proxy/pkg/log"
1112
"github.com/oklog/run"
12-
"github.com/pkg/errors"
1313
"github.com/prometheus/client_golang/prometheus"
1414
"github.com/prometheus/client_golang/prometheus/collectors"
1515
"github.com/prometheus/common/version"
@@ -40,7 +40,7 @@ func Execute() {
4040

4141
cmd, err := app.Parse(os.Args[1:])
4242
if err != nil {
43-
_, _ = fmt.Fprintln(os.Stderr, errors.Wrapf(err, "error parsing commandline arguments"))
43+
_, _ = fmt.Fprintln(os.Stderr, fmt.Errorf("error parsing commandline arguments: %w", err))
4444
app.Usage(os.Args[1:])
4545
os.Exit(2)
4646
}

cmd/server.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package cmd
22

33
import (
44
"crypto/tls"
5+
"fmt"
6+
57
"github.com/grepplabs/mqtt-proxy/apis"
68
authinst "github.com/grepplabs/mqtt-proxy/pkg/auth/instrument"
79
authnoop "github.com/grepplabs/mqtt-proxy/pkg/auth/noop"
@@ -19,7 +21,6 @@ import (
1921
"github.com/grepplabs/mqtt-proxy/pkg/tls/cert/filesource"
2022
tlscert "github.com/grepplabs/mqtt-proxy/pkg/tls/cert/source"
2123
"github.com/oklog/run"
22-
"github.com/pkg/errors"
2324
"github.com/prometheus/client_golang/prometheus"
2425
"github.com/prometheus/client_golang/prometheus/promauto"
2526
"gopkg.in/alecthomas/kingpin.v2"
@@ -122,10 +123,10 @@ func runServer(
122123
authplain.WithCredentialsFile(cfg.MQTT.Handler.Authenticator.Plain.CredentialsFile),
123124
)
124125
if err != nil {
125-
return errors.Wrap(err, "setup plain authenticator")
126+
return fmt.Errorf("setup plain authenticator: %w", err)
126127
}
127128
default:
128-
return errors.Errorf("unknown authenticator %s", cfg.MQTT.Handler.Authenticator.Name)
129+
return fmt.Errorf("unknown authenticator %s", cfg.MQTT.Handler.Authenticator.Name)
129130
}
130131
authenticator = authinst.New(authenticator, registry)
131132
defer func() {
@@ -154,10 +155,10 @@ func runServer(
154155
pubkafka.WithWorkers(cfg.MQTT.Publisher.Kafka.Workers),
155156
)
156157
if err != nil {
157-
return errors.Wrap(err, "setup kafka publisher")
158+
return fmt.Errorf("setup kafka publisher: %w", err)
158159
}
159160
default:
160-
return errors.Errorf("unknown publisher %s", cfg.MQTT.Publisher.Name)
161+
return fmt.Errorf("unknown publisher %s", cfg.MQTT.Publisher.Name)
161162
}
162163
publisher = pubinst.New(publisher, registry)
163164

@@ -187,14 +188,14 @@ func runServer(
187188
filesource.WithRefresh(cfg.MQTT.TLSSrv.Refresh),
188189
)
189190
if err != nil {
190-
return errors.Wrap(err, "setup cert file source")
191+
return fmt.Errorf("setup cert file source: %w", err)
191192
}
192193
default:
193-
return errors.Errorf("unknown cert source %s", cfg.MQTT.TLSSrv.CertSource)
194+
return fmt.Errorf("unknown cert source %s", cfg.MQTT.TLSSrv.CertSource)
194195
}
195196
tlsConfig, err = servertls.NewServerConfig(logger, source)
196197
if err != nil {
197-
return errors.Wrap(err, "setup server TLS config")
198+
return fmt.Errorf("setup server TLS config: %w", err)
198199
}
199200
}
200201

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.19
55
require (
66
github.com/confluentinc/confluent-kafka-go v1.9.2
77
github.com/oklog/run v1.1.0
8-
github.com/pkg/errors v0.9.1
98
github.com/prometheus/client_golang v1.13.0
109
github.com/prometheus/common v0.37.0
1110
github.com/stretchr/testify v1.8.1

go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ github.com/stretchr/testify v1.3.1-0.20190311161405-34c6fa2dc709/go.mod h1:M5WIy
261261
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
262262
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
263263
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
264-
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
265264
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
266265
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
267266
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=

pkg/auth/plain/option.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package plain
22

33
import (
4+
"fmt"
45
"io"
56
"os"
67

78
"encoding/csv"
8-
"github.com/pkg/errors"
99
)
1010

1111
type options struct {
@@ -75,7 +75,7 @@ func credentialsFromCSV(reader io.Reader) (map[string]string, error) {
7575
return nil, err
7676
}
7777
if len(record) != 2 {
78-
return nil, errors.Errorf("csv record username,password expected but got %v", record)
78+
return nil, fmt.Errorf("csv record username,password expected but got %v", record)
7979
}
8080
credentials[record[0]] = record[1]
8181
}

pkg/auth/plain/plain.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package plain
22

33
import (
44
"context"
5-
"github.com/pkg/errors"
5+
"fmt"
66

77
"github.com/grepplabs/mqtt-proxy/apis"
88
"github.com/grepplabs/mqtt-proxy/pkg/log"
@@ -26,7 +26,7 @@ func New(logger log.Logger, _ *prometheus.Registry, opts ...Option) (apis.UserPa
2626
for _, o := range opts {
2727
err := o.apply(&options)
2828
if err != nil {
29-
return nil, errors.Wrapf(err, "apply plain authenticator options")
29+
return nil, fmt.Errorf("apply plain authenticator options: %w", err)
3030
}
3131
}
3232

pkg/config/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package config
22

33
import (
4+
"errors"
45
"fmt"
56
"regexp"
67
"strings"
78
"time"
89

910
"github.com/confluentinc/confluent-kafka-go/kafka"
10-
"github.com/pkg/errors"
1111
)
1212

1313
// publisher names
@@ -183,20 +183,20 @@ func (c *TopicMappings) Set(value string) error {
183183
for _, pair := range strings.Split(value, ",") {
184184
kv := strings.Split(pair, "=")
185185
if len(kv) != 2 {
186-
return errors.Errorf("expected key=value, but got %s", pair)
186+
return fmt.Errorf("expected key=value, but got %s", pair)
187187
}
188188
k := strings.TrimSpace(kv[0])
189189
v := strings.TrimSpace(kv[1])
190190
if k == "" {
191-
return errors.Errorf("empty topic key %s", pair)
191+
return fmt.Errorf("empty topic key %s", pair)
192192
}
193193
if v == "" {
194-
return errors.Errorf("empty regex value %s", pair)
194+
return fmt.Errorf("empty regex value %s", pair)
195195
}
196196

197197
r, err := regexp.Compile(v)
198198
if err != nil {
199-
return errors.Wrapf(err, "invalid topic mapping regexp '%s'", v)
199+
return fmt.Errorf("invalid topic mapping regexp '%s': %w", v, err)
200200
}
201201

202202
c.Mappings = append(c.Mappings, TopicMapping{Topic: k, RegExp: r})

pkg/mqtt/codec/connack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (p *ConnackPacket) Name() string {
2020
}
2121

2222
func (p *ConnackPacket) String() string {
23-
return fmt.Sprintf("%s SessionPresent: %t ReturnCode: %d", p.FixedHeader, p.SessionPresent, p.ReturnCode)
23+
return fmt.Sprintf("%v SessionPresent: %t ReturnCode: %d", p.FixedHeader, p.SessionPresent, p.ReturnCode)
2424
}
2525

2626
func (p *ConnackPacket) Write(w io.Writer) (err error) {

pkg/mqtt/codec/connect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (p *ConnectPacket) Name() string {
3636

3737
func (p *ConnectPacket) String() string {
3838
// Password is not provided
39-
return fmt.Sprintf("%s ProtocolName: %s ProtocolLevel: %d CleanSession: %t WillFlag: %t WillQos: %d WillRetain: %t HasUsername: %t HasPassword: %t KeepAliveSeconds: %d ClientID: %s WillTopic: %s Willmessage: %s Username: %s", p.FixedHeader, p.ProtocolName, p.ProtocolLevel, p.CleanSession, p.WillFlag, p.WillQos, p.WillRetain, p.HasUsername, p.HasPassword, p.KeepAliveSeconds, p.ClientIdentifier, p.WillTopic, p.WillMessage, p.Username)
39+
return fmt.Sprintf("%v ProtocolName: %s ProtocolLevel: %d CleanSession: %t WillFlag: %t WillQos: %d WillRetain: %t HasUsername: %t HasPassword: %t KeepAliveSeconds: %d ClientID: %s WillTopic: %s Willmessage: %s Username: %s", p.FixedHeader, p.ProtocolName, p.ProtocolLevel, p.CleanSession, p.WillFlag, p.WillQos, p.WillRetain, p.HasUsername, p.HasPassword, p.KeepAliveSeconds, p.ClientIdentifier, p.WillTopic, p.WillMessage, p.Username)
4040
}
4141

4242
func (p *ConnectPacket) Write(w io.Writer) (err error) {

pkg/mqtt/codec/fixedheader.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"encoding/binary"
66
"fmt"
77
"io"
8-
9-
"github.com/pkg/errors"
108
)
119

1210
const maxRemainingLength = 268435455
@@ -25,10 +23,10 @@ func (fh *FixedHeader) MessageName() string {
2523

2624
func (fh *FixedHeader) validate() error {
2725
if fh.RemainingLength < 0 {
28-
return errors.Errorf("negative remaining length %d", fh.RemainingLength)
26+
return fmt.Errorf("negative remaining length %d", fh.RemainingLength)
2927
}
3028
if fh.RemainingLength > maxRemainingLength {
31-
return errors.Errorf("the maximum remaining length is %d, but was %d", maxRemainingLength, fh.RemainingLength)
29+
return fmt.Errorf("the maximum remaining length is %d, but was %d", maxRemainingLength, fh.RemainingLength)
3230
}
3331
return nil
3432
}
@@ -58,7 +56,7 @@ func (fh *FixedHeader) pack() bytes.Buffer {
5856
return header
5957
}
6058

61-
func (fh FixedHeader) String() string {
59+
func (fh *FixedHeader) String() string {
6260
return fmt.Sprintf("%s: Dup: %t QoS: %s Retain: %t rLength: %d", MqttMessageTypeNames[fh.MessageType], fh.Dup, MqttQoSNames[fh.Qos], fh.Retain, fh.RemainingLength)
6361
}
6462

@@ -94,7 +92,7 @@ func decodeLength(r io.Reader) (int, error) {
9492
return 0, err
9593
}
9694
if byteReader.bytesRead > 4 {
97-
return 0, errors.Errorf("the maximum number of bytes in the remaining length is 4, but was %d", byteReader.bytesRead)
95+
return 0, fmt.Errorf("the maximum number of bytes in the remaining length is 4, but was %d", byteReader.bytesRead)
9896
}
9997
return int(remainingLength), nil
10098
}

0 commit comments

Comments
 (0)