Skip to content

Commit 0b267d5

Browse files
committed
Remove deprecated github.com/pkg/errors module
Signed-off-by: Sylvain Rabot <[email protected]>
1 parent def5474 commit 0b267d5

File tree

11 files changed

+59
-69
lines changed

11 files changed

+59
-69
lines changed

datadictionary/datadictionary.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ package datadictionary
33

44
import (
55
"encoding/xml"
6+
"fmt"
67
"io"
78
"os"
8-
9-
"github.com/pkg/errors"
109
)
1110

1211
// DataDictionary models FIX messages, components, and fields.
@@ -304,7 +303,7 @@ func Parse(path string) (*DataDictionary, error) {
304303
var err error
305304
xmlFile, err = os.Open(path)
306305
if err != nil {
307-
return nil, errors.Wrapf(err, "problem opening file: %v", path)
306+
return nil, fmt.Errorf("problem opening file: %s: %w", path, err)
308307
}
309308
defer xmlFile.Close()
310309

@@ -320,7 +319,7 @@ func ParseSrc(xmlSrc io.Reader) (*DataDictionary, error) {
320319
}
321320

322321
if err := decoder.Decode(doc); err != nil {
323-
return nil, errors.Wrapf(err, "problem parsing XML file")
322+
return nil, fmt.Errorf("problem parsing XML file: %w", err)
324323
}
325324

326325
b := new(builder)

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.23
55
require (
66
github.com/mattn/go-sqlite3 v1.14.22
77
github.com/pires/go-proxyproto v0.7.0
8-
github.com/pkg/errors v0.9.1
98
github.com/quagmt/udecimal v1.8.0
109
github.com/shopspring/decimal v1.4.0
1110
github.com/stretchr/testify v1.9.0

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ github.com/montanaflynn/stats v0.6.6 h1:Duep6KMIDpY4Yo11iFsvyqJDyfzLF9+sndUKT+v6
1919
github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
2020
github.com/pires/go-proxyproto v0.7.0 h1:IukmRewDQFWC7kfnb66CSomk2q/seBuilHBYFwyq0Hs=
2121
github.com/pires/go-proxyproto v0.7.0/go.mod h1:Vz/1JPY/OACxWGQNIRY2BeyDmpoaWmEP40O9LbuiFR4=
22-
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
23-
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
2422
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2523
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2624
github.com/quagmt/udecimal v1.8.0 h1:d4MJNGb/dg8r03AprkeSiDlVKtkZnL10L3de/YGOiiI=

internal/time_range.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package internal
22

33
import (
4+
"errors"
5+
"fmt"
46
"time"
5-
6-
"github.com/pkg/errors"
77
)
88

99
// TimeOfDay represents the time of day.
@@ -27,7 +27,7 @@ func NewTimeOfDay(hour, minute, second int) TimeOfDay {
2727
func ParseTimeOfDay(str string) (TimeOfDay, error) {
2828
t, err := time.Parse(shortForm, str)
2929
if err != nil {
30-
return TimeOfDay{}, errors.Wrap(err, "time must be in the format HH:MM:SS")
30+
return TimeOfDay{}, fmt.Errorf("time must be in the format HH:MM:SS: %w", err)
3131
}
3232

3333
return NewTimeOfDay(t.Clock()), nil

log/mongo/mongo_log.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"log"
2222
"time"
2323

24-
"github.com/pkg/errors"
2524
"go.mongodb.org/mongo-driver/bson"
2625
"go.mongodb.org/mongo-driver/mongo"
2726
"go.mongodb.org/mongo-driver/mongo/options"
@@ -214,7 +213,7 @@ func (l *mongoLog) close() error {
214213
if l.db != nil {
215214
err := l.db.Disconnect(context.Background())
216215
if err != nil {
217-
return errors.Wrap(err, "error disconnecting from database")
216+
return fmt.Errorf("error disconnecting from database: %w", err)
218217
}
219218
l.db = nil
220219
}

memory_store.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
package quickfix
1717

1818
import (
19+
"fmt"
1920
"time"
20-
21-
"github.com/pkg/errors"
2221
)
2322

2423
type memoryStore struct {
@@ -122,7 +121,7 @@ type memoryStoreFactory struct{}
122121
func (f memoryStoreFactory) Create(_ SessionID) (MessageStore, error) {
123122
m := new(memoryStore)
124123
if err := m.Reset(); err != nil {
125-
return m, errors.Wrap(err, "reset")
124+
return m, fmt.Errorf("reset: %w", err)
126125
}
127126
return m, nil
128127
}

session_factory.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
package quickfix
1717

1818
import (
19+
"errors"
20+
"fmt"
1921
"net"
2022
"strconv"
2123
"strings"
2224
"time"
2325

24-
"github.com/pkg/errors"
25-
2626
"github.com/quickfixgo/quickfix/config"
2727
"github.com/quickfixgo/quickfix/datadictionary"
2828
"github.com/quickfixgo/quickfix/internal"
@@ -132,17 +132,17 @@ func (f sessionFactory) newSession(
132132
}
133133

134134
if s.transportDataDictionary, err = datadictionary.Parse(transportDataDictionaryPath); err != nil {
135-
err = errors.Wrapf(
136-
err, "problem parsing XML datadictionary path '%v' for setting '%v",
137-
settings.settings[config.TransportDataDictionary], config.TransportDataDictionary,
135+
err = fmt.Errorf(
136+
"problem parsing XML datadictionary path '%v' for setting '%v': %w",
137+
settings.settings[config.TransportDataDictionary], config.TransportDataDictionary, err,
138138
)
139139
return
140140
}
141141

142142
if s.appDataDictionary, err = datadictionary.Parse(appDataDictionaryPath); err != nil {
143-
err = errors.Wrapf(
144-
err, "problem parsing XML datadictionary path '%v' for setting '%v",
145-
settings.settings[config.AppDataDictionary], config.AppDataDictionary,
143+
err = fmt.Errorf(
144+
"problem parsing XML datadictionary path '%v' for setting '%v': %w",
145+
settings.settings[config.AppDataDictionary], config.AppDataDictionary, err,
146146
)
147147
return
148148
}
@@ -156,9 +156,9 @@ func (f sessionFactory) newSession(
156156
}
157157

158158
if s.appDataDictionary, err = datadictionary.Parse(dataDictionaryPath); err != nil {
159-
err = errors.Wrapf(
160-
err, "problem parsing XML datadictionary path '%v' for setting '%v",
161-
settings.settings[config.DataDictionary], config.DataDictionary,
159+
err = fmt.Errorf(
160+
"problem parsing XML datadictionary path '%v' for setting '%v': %w",
161+
settings.settings[config.DataDictionary], config.DataDictionary, err,
162162
)
163163
return
164164
}
@@ -245,17 +245,17 @@ func (f sessionFactory) newSession(
245245

246246
var start, end internal.TimeOfDay
247247
if start, err = internal.ParseTimeOfDay(startTimeStr); err != nil {
248-
err = errors.Wrapf(
249-
err, "problem parsing time of day '%v' for setting '%v",
250-
settings.settings[config.StartTime], config.StartTime,
248+
err = fmt.Errorf(
249+
"problem parsing time of day '%v' for setting '%v': %w",
250+
settings.settings[config.StartTime], config.StartTime, err,
251251
)
252252
return
253253
}
254254

255255
if end, err = internal.ParseTimeOfDay(endTimeStr); err != nil {
256-
err = errors.Wrapf(
257-
err, "problem parsing time of day '%v' for setting '%v",
258-
settings.settings[config.EndTime], config.EndTime,
256+
err = fmt.Errorf(
257+
"problem parsing time of day '%v' for setting '%v': %w",
258+
settings.settings[config.EndTime], config.EndTime, err,
259259
)
260260
return
261261
}
@@ -269,9 +269,9 @@ func (f sessionFactory) newSession(
269269

270270
loc, err = time.LoadLocation(locStr)
271271
if err != nil {
272-
err = errors.Wrapf(
273-
err, "problem parsing time zone '%v' for setting '%v",
274-
settings.settings[config.TimeZone], config.TimeZone,
272+
err = fmt.Errorf(
273+
"problem parsing time zone '%v' for setting '%v': %w",
274+
settings.settings[config.TimeZone], config.TimeZone, err,
275275
)
276276
return
277277
}

store/file/file_store.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package file
1717

1818
import (
19+
"errors"
1920
"fmt"
2021
"io"
2122
"os"
@@ -25,7 +26,6 @@ import (
2526
"sync"
2627
"time"
2728

28-
"github.com/pkg/errors"
2929
"github.com/quickfixgo/quickfix"
3030
"github.com/quickfixgo/quickfix/config"
3131
)
@@ -96,7 +96,7 @@ func newFileStore(sessionID quickfix.SessionID, dirname string, fileSync bool) (
9696

9797
memStore, memErr := quickfix.NewMemoryStoreFactory().Create(sessionID)
9898
if memErr != nil {
99-
return nil, errors.Wrap(memErr, "cache creation")
99+
return nil, fmt.Errorf("cache creation: %w", memErr)
100100
}
101101

102102
store := &fileStore{
@@ -120,11 +120,11 @@ func newFileStore(sessionID quickfix.SessionID, dirname string, fileSync bool) (
120120
// Reset deletes the store files and sets the seqnums back to 1.
121121
func (store *fileStore) Reset() error {
122122
if err := store.cache.Reset(); err != nil {
123-
return errors.Wrap(err, "cache reset")
123+
return fmt.Errorf("cache reset: %w", err)
124124
}
125125

126126
if err := store.Close(); err != nil {
127-
return errors.Wrap(err, "close")
127+
return fmt.Errorf("close: %w", err)
128128
}
129129
if err := removeFile(store.bodyFname); err != nil {
130130
return err
@@ -147,7 +147,7 @@ func (store *fileStore) Reset() error {
147147
// Refresh closes the store files and then reloads from them.
148148
func (store *fileStore) Refresh() (err error) {
149149
if err = store.cache.Reset(); err != nil {
150-
err = errors.Wrap(err, "cache reset")
150+
err = fmt.Errorf("cache reset: %w", err)
151151
return
152152
}
153153

@@ -183,11 +183,11 @@ func (store *fileStore) Refresh() (err error) {
183183
}
184184

185185
if err := store.SetNextSenderMsgSeqNum(store.NextSenderMsgSeqNum()); err != nil {
186-
return errors.Wrap(err, "set next sender")
186+
return fmt.Errorf("set next sender: %w", err)
187187
}
188188

189189
if err := store.SetNextTargetMsgSeqNum(store.NextTargetMsgSeqNum()); err != nil {
190-
return errors.Wrap(err, "set next target")
190+
return fmt.Errorf("set next target: %w", err)
191191
}
192192
return nil
193193
}
@@ -204,15 +204,15 @@ func (store *fileStore) populateCache() (creationTimePopulated bool, err error)
204204
if senderSeqNumBytes, err := os.ReadFile(store.senderSeqNumsFname); err == nil {
205205
if senderSeqNum, err := strconv.Atoi(strings.Trim(string(senderSeqNumBytes), "\r\n")); err == nil {
206206
if err = store.cache.SetNextSenderMsgSeqNum(senderSeqNum); err != nil {
207-
return creationTimePopulated, errors.Wrap(err, "cache set next sender")
207+
return creationTimePopulated, fmt.Errorf("cache set next sender: %w", err)
208208
}
209209
}
210210
}
211211

212212
if targetSeqNumBytes, err := os.ReadFile(store.targetSeqNumsFname); err == nil {
213213
if targetSeqNum, err := strconv.Atoi(strings.Trim(string(targetSeqNumBytes), "\r\n")); err == nil {
214214
if err = store.cache.SetNextTargetMsgSeqNum(targetSeqNum); err != nil {
215-
return creationTimePopulated, errors.Wrap(err, "cache set next target")
215+
return creationTimePopulated, fmt.Errorf("cache set next target: %w", err)
216216
}
217217
}
218218
}
@@ -273,31 +273,31 @@ func (store *fileStore) NextTargetMsgSeqNum() int {
273273
// SetNextSenderMsgSeqNum sets the next MsgSeqNum that will be sent.
274274
func (store *fileStore) SetNextSenderMsgSeqNum(next int) error {
275275
if err := store.setSeqNum(store.senderSeqNumsFile, next); err != nil {
276-
return errors.Wrap(err, "file")
276+
return fmt.Errorf("file: %w", err)
277277
}
278278
return store.cache.SetNextSenderMsgSeqNum(next)
279279
}
280280

281281
// SetNextTargetMsgSeqNum sets the next MsgSeqNum that should be received.
282282
func (store *fileStore) SetNextTargetMsgSeqNum(next int) error {
283283
if err := store.setSeqNum(store.targetSeqNumsFile, next); err != nil {
284-
return errors.Wrap(err, "file")
284+
return fmt.Errorf("file: %w", err)
285285
}
286286
return store.cache.SetNextTargetMsgSeqNum(next)
287287
}
288288

289289
// IncrNextSenderMsgSeqNum increments the next MsgSeqNum that will be sent.
290290
func (store *fileStore) IncrNextSenderMsgSeqNum() error {
291291
if err := store.SetNextSenderMsgSeqNum(store.cache.NextSenderMsgSeqNum() + 1); err != nil {
292-
return errors.Wrap(err, "file")
292+
return fmt.Errorf("file: %w", err)
293293
}
294294
return nil
295295
}
296296

297297
// IncrNextTargetMsgSeqNum increments the next MsgSeqNum that should be received.
298298
func (store *fileStore) IncrNextTargetMsgSeqNum() error {
299299
if err := store.SetNextTargetMsgSeqNum(store.cache.NextTargetMsgSeqNum() + 1); err != nil {
300-
return errors.Wrap(err, "file")
300+
return fmt.Errorf("file: %w", err)
301301
}
302302
return nil
303303
}

store/file/util.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"os"
2121
"strings"
2222

23-
"github.com/pkg/errors"
2423
"github.com/quickfixgo/quickfix"
2524
)
2625

@@ -68,7 +67,7 @@ func closeSyncFile(f *os.File) error {
6867
// removeFile behaves like os.Remove, except that no error is returned if the file does not exist.
6968
func removeFile(fname string) error {
7069
if err := os.Remove(fname); (err != nil) && !os.IsNotExist(err) {
71-
return errors.Wrapf(err, "remove %v", fname)
70+
return fmt.Errorf("remove %v: %w", fname, err)
7271
}
7372
return nil
7473
}

0 commit comments

Comments
 (0)