Skip to content

Commit a9a63e2

Browse files
authored
chore(deps): remove dependency on github.com/pkg/errors (#2184)
1 parent 987f17d commit a9a63e2

23 files changed

+68
-89
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
66

77
## [Unreleased]
88

9+
- chore(deps): Remove dependency on github.com/pkg/errors (#2184)
910
- chore(deps): Migrate from OpenCensus to OpenTelemetry (#2169)
1011

1112
## [4.5.1] - 2025-01-21

backup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"bytes"
1111
"context"
1212
"encoding/binary"
13+
"fmt"
1314
"io"
1415

15-
"github.com/pkg/errors"
1616
"google.golang.org/protobuf/proto"
1717

1818
"github.com/dgraph-io/badger/v4/pb"
@@ -61,7 +61,7 @@ func (stream *Stream) Backup(w io.Writer, since uint64) (uint64, error) {
6161
return list, nil
6262
}
6363
if item.Version() < since {
64-
return nil, errors.Errorf("Backup: Item Version: %d less than sinceTs: %d",
64+
return nil, fmt.Errorf("Backup: Item Version: %d less than sinceTs: %d",
6565
item.Version(), since)
6666
}
6767

badger/cmd/flatten.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
package cmd
77

88
import (
9+
"errors"
910
"fmt"
1011
"math"
1112

12-
"github.com/pkg/errors"
1313
"github.com/spf13/cobra"
1414

1515
"github.com/dgraph-io/badger/v4"
@@ -57,7 +57,7 @@ func flatten(cmd *cobra.Command, args []string) error {
5757
return err
5858
}
5959
if fo.compressionType > 2 {
60-
return errors.Errorf(
60+
return errors.New(
6161
"compression value must be one of 0 (disabled), 1 (Snappy), or 2 (ZSTD)")
6262
}
6363
opt := badger.DefaultOptions(sstDir).

badger/cmd/info.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"time"
1818

1919
humanize "github.com/dustin/go-humanize"
20-
"github.com/pkg/errors"
2120
"github.com/spf13/cobra"
2221

2322
"github.com/dgraph-io/badger/v4"
@@ -198,7 +197,7 @@ func lookup(db *badger.DB) error {
198197

199198
itr.Rewind()
200199
if !itr.Valid() {
201-
return errors.Errorf("Unable to rewind to key:\n%s", hex.Dump(key))
200+
return fmt.Errorf("Unable to rewind to key:\n%s", hex.Dump(key))
202201
}
203202
fmt.Println()
204203
item := itr.Item()

badger/cmd/read_bench.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ package cmd
77

88
import (
99
"context"
10+
"errors"
1011
"fmt"
1112
"math"
1213
"math/rand"
1314
"sync/atomic"
1415
"time"
1516

1617
humanize "github.com/dustin/go-humanize"
17-
"github.com/pkg/errors"
1818
"github.com/spf13/cobra"
1919
"google.golang.org/protobuf/proto"
2020

@@ -195,7 +195,7 @@ func getSampleKeys(db *badger.DB, sampleSize int) ([][]byte, error) {
195195
return l, nil
196196
}
197197

198-
errStop := errors.Errorf("Stop iterating")
198+
errStop := errors.New("Stop iterating")
199199
ctx, cancel := context.WithCancel(context.Background())
200200
defer cancel()
201201
stream.Send = func(buf *z.Buffer) error {

badger/cmd/stream.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
package cmd
77

88
import (
9+
"errors"
910
"fmt"
1011
"io"
1112
"math"
1213
"os"
1314

14-
"github.com/pkg/errors"
1515
"github.com/spf13/cobra"
1616

1717
"github.com/dgraph-io/badger/v4"
@@ -75,7 +75,7 @@ func stream(cmd *cobra.Command, args []string) error {
7575

7676
// Options for output DB.
7777
if so.compressionType > 2 {
78-
return errors.Errorf(
78+
return errors.New(
7979
"compression value must be one of 0 (disabled), 1 (Snappy), or 2 (ZSTD)")
8080
}
8181
inDB, err := badger.OpenManaged(inOpt)
@@ -96,7 +96,7 @@ func stream(cmd *cobra.Command, args []string) error {
9696

9797
_, err = f.Readdirnames(1)
9898
if err != io.EOF {
99-
return errors.Errorf(
99+
return fmt.Errorf(
100100
"cannot run stream tool on non-empty output directory %s", so.outDir)
101101
}
102102
}

batch.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
package badger
77

88
import (
9+
"errors"
10+
"fmt"
911
"sync"
1012
"sync/atomic"
1113

12-
"github.com/pkg/errors"
1314
"google.golang.org/protobuf/proto"
1415

1516
"github.com/dgraph-io/badger/v4/pb"
@@ -220,7 +221,7 @@ func (wb *WriteBatch) Flush() error {
220221

221222
if err := wb.throttle.Finish(); err != nil {
222223
if wb.Error() != nil {
223-
return errors.Errorf("wb.err: %s err: %s", wb.Error(), err)
224+
return fmt.Errorf("wb.err: %w err: %w", wb.Error(), err)
224225
}
225226
return err
226227
}

db.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"bytes"
1010
"context"
1111
"encoding/binary"
12-
stderrors "errors"
12+
"errors"
1313
"expvar"
1414
"fmt"
1515
"math"
@@ -22,7 +22,6 @@ import (
2222
"time"
2323

2424
humanize "github.com/dustin/go-humanize"
25-
"github.com/pkg/errors"
2625

2726
"github.com/dgraph-io/badger/v4/fb"
2827
"github.com/dgraph-io/badger/v4/options"
@@ -145,14 +144,14 @@ func checkAndSetOptions(opt *Options) error {
145144

146145
// We are limiting opt.ValueThreshold to maxValueThreshold for now.
147146
if opt.ValueThreshold > maxValueThreshold {
148-
return errors.Errorf("Invalid ValueThreshold, must be less or equal to %d",
147+
return fmt.Errorf("Invalid ValueThreshold, must be less or equal to %d",
149148
maxValueThreshold)
150149
}
151150

152151
// If ValueThreshold is greater than opt.maxBatchSize, we won't be able to push any data using
153152
// the transaction APIs. Transaction batches entries into batches of size opt.maxBatchSize.
154153
if opt.ValueThreshold > opt.maxBatchSize {
155-
return errors.Errorf("Valuethreshold %d greater than max batch size of %d. Either "+
154+
return fmt.Errorf("Valuethreshold %d greater than max batch size of %d. Either "+
156155
"reduce opt.ValueThreshold or increase opt.BaseTableSize.",
157156
opt.ValueThreshold, opt.maxBatchSize)
158157
}
@@ -373,7 +372,7 @@ func Open(opt Options) (*DB, error) {
373372
go db.threshold.listenForValueThresholdUpdate()
374373

375374
if err := db.initBannedNamespaces(); err != nil {
376-
return db, errors.Wrapf(err, "While setting banned keys")
375+
return db, fmt.Errorf("While setting banned keys: %w", err)
377376
}
378377

379378
db.closers.writes = z.NewCloser(1)
@@ -787,7 +786,7 @@ func (db *DB) writeToLSM(b *request) error {
787786
// running in InMemory mode. In InMemory mode, we don't write anything to the
788787
// value log and that's why the length of b.Ptrs will always be zero.
789788
if !db.opt.InMemory && len(b.Ptrs) != len(b.Entries) {
790-
return errors.Errorf("Ptrs and Entries don't match: %+v", b)
789+
return fmt.Errorf("Ptrs and Entries don't match: %+v", b)
791790
}
792791

793792
for i, entry := range b.Entries {
@@ -1005,7 +1004,7 @@ func (db *DB) batchSetAsync(entries []*Entry, f func(error)) error {
10051004
return nil
10061005
}
10071006

1008-
var errNoRoom = stderrors.New("No room for write")
1007+
var errNoRoom = errors.New("No room for write")
10091008

10101009
// ensureRoomForWrite is always called serially.
10111010
func (db *DB) ensureRoomForWrite() error {
@@ -1963,7 +1962,7 @@ func createDirs(opt Options) error {
19631962
}
19641963
if !dirExists {
19651964
if opt.ReadOnly {
1966-
return errors.Errorf("Cannot find directory %q for read-only open", path)
1965+
return fmt.Errorf("Cannot find directory %q for read-only open", path)
19671966
}
19681967
// Try to create the directory
19691968
err = os.MkdirAll(path, 0700)
@@ -2035,7 +2034,7 @@ func (db *DB) CacheMaxCost(cache CacheType, maxCost int64) (int64, error) {
20352034
case IndexCache:
20362035
return db.indexCache.MaxCost(), nil
20372036
default:
2038-
return 0, errors.Errorf("invalid cache type")
2037+
return 0, errors.New("invalid cache type")
20392038
}
20402039
}
20412040

@@ -2047,7 +2046,7 @@ func (db *DB) CacheMaxCost(cache CacheType, maxCost int64) (int64, error) {
20472046
db.indexCache.UpdateMaxCost(maxCost)
20482047
return maxCost, nil
20492048
default:
2050-
return 0, errors.Errorf("invalid cache type")
2049+
return 0, errors.New("invalid cache type")
20512050
}
20522051
}
20532052

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ toolchain go1.24.1
66

77
require (
88
github.com/cespare/xxhash/v2 v2.3.0
9-
github.com/dgraph-io/ristretto/v2 v2.1.0
9+
github.com/dgraph-io/ristretto/v2 v2.2.0
1010
github.com/dustin/go-humanize v1.0.1
1111
github.com/google/flatbuffers v25.2.10+incompatible
1212
github.com/klauspost/compress v1.18.0
13-
github.com/pkg/errors v0.9.1
1413
github.com/spf13/cobra v1.9.1
1514
github.com/stretchr/testify v1.10.0
1615
go.opentelemetry.io/contrib/zpages v0.60.0

go.sum

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
33
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
44
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
55
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6-
github.com/dgraph-io/ristretto/v2 v2.1.0 h1:59LjpOJLNDULHh8MC4UaegN52lC4JnO2dITsie/Pa8I=
7-
github.com/dgraph-io/ristretto/v2 v2.1.0/go.mod h1:uejeqfYXpUomfse0+lO+13ATz4TypQYLJZzBSAemuB4=
8-
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y=
9-
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
6+
github.com/dgraph-io/ristretto/v2 v2.2.0 h1:bkY3XzJcXoMuELV8F+vS8kzNgicwQFAaGINAEJdWGOM=
7+
github.com/dgraph-io/ristretto/v2 v2.2.0/go.mod h1:RZrm63UmcBAaYWC1DotLYBmTvgkrs0+XhBd7Npn7/zI=
8+
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da h1:aIftn67I1fkbMa512G+w+Pxci9hJPB8oMnkcP3iZF38=
9+
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
1010
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
1111
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
1212
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
@@ -28,8 +28,6 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
2828
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
2929
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
3030
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
31-
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
32-
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
3331
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3432
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3533
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=

levels.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"bytes"
1010
"context"
1111
"encoding/hex"
12-
stderrors "errors"
12+
"errors"
1313
"fmt"
1414
"math"
1515
"math/rand"
@@ -20,7 +20,6 @@ import (
2020
"sync/atomic"
2121
"time"
2222

23-
"github.com/pkg/errors"
2423
"go.opentelemetry.io/otel"
2524
"go.opentelemetry.io/otel/attribute"
2625

@@ -1502,7 +1501,7 @@ func tablesToString(tables []*table.Table) []string {
15021501
return res
15031502
}
15041503

1505-
var errFillTables = stderrors.New("Unable to fill tables")
1504+
var errFillTables = errors.New("Unable to fill tables")
15061505

15071506
// doCompact picks some table on level l and compacts it away to the next level.
15081507
func (s *levelsController) doCompact(id int, p compactionPriority) error {

manifest.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"bufio"
1010
"bytes"
1111
"encoding/binary"
12-
stderrors "errors"
12+
"errors"
1313
"fmt"
1414
"hash/crc32"
1515
"io"
@@ -18,7 +18,6 @@ import (
1818
"path/filepath"
1919
"sync"
2020

21-
"github.com/pkg/errors"
2221
"google.golang.org/protobuf/proto"
2322

2423
"github.com/dgraph-io/badger/v4/options"
@@ -342,8 +341,8 @@ func (r *countingReader) ReadByte() (b byte, err error) {
342341
}
343342

344343
var (
345-
errBadMagic = stderrors.New("manifest has bad magic")
346-
errBadChecksum = stderrors.New("manifest has checksum mismatch")
344+
errBadMagic = errors.New("manifest has bad magic")
345+
errBadChecksum = errors.New("manifest has checksum mismatch")
347346
)
348347

349348
// ReplayManifestFile reads the manifest file and constructs two manifest objects. (We need one
@@ -399,7 +398,7 @@ func ReplayManifestFile(fp *os.File, extMagic uint16) (Manifest, int64, error) {
399398
length := y.BytesToU32(lenCrcBuf[0:4])
400399
// Sanity check to ensure we don't over-allocate memory.
401400
if length > uint32(stat.Size()) {
402-
return Manifest{}, 0, errors.Errorf(
401+
return Manifest{}, 0, fmt.Errorf(
403402
"Buffer length: %d greater than file size: %d. Manifest file might be corrupted",
404403
length, stat.Size())
405404
}

memtable.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222
"sync"
2323
"sync/atomic"
2424

25-
"github.com/pkg/errors"
26-
2725
"github.com/dgraph-io/badger/v4/pb"
2826
"github.com/dgraph-io/badger/v4/skl"
2927
"github.com/dgraph-io/badger/v4/y"
@@ -147,7 +145,7 @@ func (db *DB) newMemTable() (*memTable, error) {
147145
db.opt.Errorf("Got error: %v for id: %d\n", err, db.nextMemFid)
148146
return nil, y.Wrapf(err, "newMemTable")
149147
}
150-
return nil, errors.Errorf("File %s already exists", mt.wal.Fd.Name())
148+
return nil, fmt.Errorf("File %s already exists", mt.wal.Fd.Name())
151149
}
152150

153151
func (db *DB) mtFilePath(fid int) string {

options.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
"strings"
1414
"time"
1515

16-
"github.com/pkg/errors"
17-
1816
"github.com/dgraph-io/badger/v4/options"
1917
"github.com/dgraph-io/badger/v4/table"
2018
"github.com/dgraph-io/badger/v4/y"
@@ -234,10 +232,10 @@ func parseCompression(cStr string) (options.CompressionType, int, error) {
234232
y.Check(err)
235233
if level <= 0 {
236234
return 0, 0,
237-
errors.Errorf("ERROR: compression level(%v) must be greater than zero", level)
235+
fmt.Errorf("ERROR: compression level(%v) must be greater than zero", level)
238236
}
239237
} else if len(cStrSplit) > 2 {
240-
return 0, 0, errors.Errorf("ERROR: Invalid badger.compression argument")
238+
return 0, 0, fmt.Errorf("ERROR: Invalid badger.compression argument")
241239
}
242240
switch cType {
243241
case "zstd":
@@ -247,7 +245,7 @@ func parseCompression(cStr string) (options.CompressionType, int, error) {
247245
case "none":
248246
return options.None, 0, nil
249247
}
250-
return 0, 0, errors.Errorf("ERROR: compression type (%s) invalid", cType)
248+
return 0, 0, fmt.Errorf("ERROR: compression type (%s) invalid", cType)
251249
}
252250

253251
// generateSuperFlag generates an identical SuperFlag string from the provided Options.

publisher_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ package badger
77

88
import (
99
"context"
10+
"errors"
1011
"fmt"
1112
"runtime"
1213
"sync"
1314
"sync/atomic"
1415
"testing"
1516

16-
"github.com/pkg/errors"
1717
"github.com/stretchr/testify/require"
1818

1919
"github.com/dgraph-io/badger/v4/pb"

0 commit comments

Comments
 (0)