Skip to content

chore(deps): remove dependency on github.com/pkg/errors #2184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## [Unreleased]

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

## [4.5.1] - 2025-01-21
Expand Down
4 changes: 2 additions & 2 deletions backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"bytes"
"context"
"encoding/binary"
"fmt"
"io"

"github.com/pkg/errors"
"google.golang.org/protobuf/proto"

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

Expand Down
4 changes: 2 additions & 2 deletions badger/cmd/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
package cmd

import (
"errors"
"fmt"
"math"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/dgraph-io/badger/v4"
Expand Down Expand Up @@ -57,7 +57,7 @@ func flatten(cmd *cobra.Command, args []string) error {
return err
}
if fo.compressionType > 2 {
return errors.Errorf(
return errors.New(
"compression value must be one of 0 (disabled), 1 (Snappy), or 2 (ZSTD)")
}
opt := badger.DefaultOptions(sstDir).
Expand Down
3 changes: 1 addition & 2 deletions badger/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"time"

humanize "github.com/dustin/go-humanize"
"github.com/pkg/errors"
"github.com/spf13/cobra"

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

itr.Rewind()
if !itr.Valid() {
return errors.Errorf("Unable to rewind to key:\n%s", hex.Dump(key))
return fmt.Errorf("Unable to rewind to key:\n%s", hex.Dump(key))
}
fmt.Println()
item := itr.Item()
Expand Down
4 changes: 2 additions & 2 deletions badger/cmd/read_bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ package cmd

import (
"context"
"errors"
"fmt"
"math"
"math/rand"
"sync/atomic"
"time"

humanize "github.com/dustin/go-humanize"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"google.golang.org/protobuf/proto"

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

errStop := errors.Errorf("Stop iterating")
errStop := errors.New("Stop iterating")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
stream.Send = func(buf *z.Buffer) error {
Expand Down
6 changes: 3 additions & 3 deletions badger/cmd/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
package cmd

import (
"errors"
"fmt"
"io"
"math"
"os"

"github.com/pkg/errors"
"github.com/spf13/cobra"

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

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

_, err = f.Readdirnames(1)
if err != io.EOF {
return errors.Errorf(
return fmt.Errorf(
"cannot run stream tool on non-empty output directory %s", so.outDir)
}
}
Expand Down
5 changes: 3 additions & 2 deletions batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
package badger

import (
"errors"
"fmt"
"sync"
"sync/atomic"

"github.com/pkg/errors"
"google.golang.org/protobuf/proto"

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

if err := wb.throttle.Finish(); err != nil {
if wb.Error() != nil {
return errors.Errorf("wb.err: %s err: %s", wb.Error(), err)
return fmt.Errorf("wb.err: %w err: %w", wb.Error(), err)
}
return err
}
Expand Down
19 changes: 9 additions & 10 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"bytes"
"context"
"encoding/binary"
stderrors "errors"
"errors"
"expvar"
"fmt"
"math"
Expand All @@ -22,7 +22,6 @@ import (
"time"

humanize "github.com/dustin/go-humanize"
"github.com/pkg/errors"

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

// We are limiting opt.ValueThreshold to maxValueThreshold for now.
if opt.ValueThreshold > maxValueThreshold {
return errors.Errorf("Invalid ValueThreshold, must be less or equal to %d",
return fmt.Errorf("Invalid ValueThreshold, must be less or equal to %d",
maxValueThreshold)
}

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

if err := db.initBannedNamespaces(); err != nil {
return db, errors.Wrapf(err, "While setting banned keys")
return db, fmt.Errorf("While setting banned keys: %w", err)
}

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

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

var errNoRoom = stderrors.New("No room for write")
var errNoRoom = errors.New("No room for write")

// ensureRoomForWrite is always called serially.
func (db *DB) ensureRoomForWrite() error {
Expand Down Expand Up @@ -1963,7 +1962,7 @@ func createDirs(opt Options) error {
}
if !dirExists {
if opt.ReadOnly {
return errors.Errorf("Cannot find directory %q for read-only open", path)
return fmt.Errorf("Cannot find directory %q for read-only open", path)
}
// Try to create the directory
err = os.MkdirAll(path, 0700)
Expand Down Expand Up @@ -2035,7 +2034,7 @@ func (db *DB) CacheMaxCost(cache CacheType, maxCost int64) (int64, error) {
case IndexCache:
return db.indexCache.MaxCost(), nil
default:
return 0, errors.Errorf("invalid cache type")
return 0, errors.New("invalid cache type")
}
}

Expand All @@ -2047,7 +2046,7 @@ func (db *DB) CacheMaxCost(cache CacheType, maxCost int64) (int64, error) {
db.indexCache.UpdateMaxCost(maxCost)
return maxCost, nil
default:
return 0, errors.Errorf("invalid cache type")
return 0, errors.New("invalid cache type")
}
}

Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ toolchain go1.24.1

require (
github.com/cespare/xxhash/v2 v2.3.0
github.com/dgraph-io/ristretto/v2 v2.1.0
github.com/dgraph-io/ristretto/v2 v2.2.0
github.com/dustin/go-humanize v1.0.1
github.com/google/flatbuffers v25.2.10+incompatible
github.com/klauspost/compress v1.18.0
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.9.1
github.com/stretchr/testify v1.10.0
go.opentelemetry.io/contrib/zpages v0.60.0
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgraph-io/ristretto/v2 v2.1.0 h1:59LjpOJLNDULHh8MC4UaegN52lC4JnO2dITsie/Pa8I=
github.com/dgraph-io/ristretto/v2 v2.1.0/go.mod h1:uejeqfYXpUomfse0+lO+13ATz4TypQYLJZzBSAemuB4=
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y=
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgraph-io/ristretto/v2 v2.2.0 h1:bkY3XzJcXoMuELV8F+vS8kzNgicwQFAaGINAEJdWGOM=
github.com/dgraph-io/ristretto/v2 v2.2.0/go.mod h1:RZrm63UmcBAaYWC1DotLYBmTvgkrs0+XhBd7Npn7/zI=
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da h1:aIftn67I1fkbMa512G+w+Pxci9hJPB8oMnkcP3iZF38=
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand All @@ -28,8 +28,6 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
Expand Down
5 changes: 2 additions & 3 deletions levels.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"bytes"
"context"
"encoding/hex"
stderrors "errors"
"errors"
"fmt"
"math"
"math/rand"
Expand All @@ -20,7 +20,6 @@ import (
"sync/atomic"
"time"

"github.com/pkg/errors"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"

Expand Down Expand Up @@ -1502,7 +1501,7 @@ func tablesToString(tables []*table.Table) []string {
return res
}

var errFillTables = stderrors.New("Unable to fill tables")
var errFillTables = errors.New("Unable to fill tables")

// doCompact picks some table on level l and compacts it away to the next level.
func (s *levelsController) doCompact(id int, p compactionPriority) error {
Expand Down
9 changes: 4 additions & 5 deletions manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"bufio"
"bytes"
"encoding/binary"
stderrors "errors"
"errors"
"fmt"
"hash/crc32"
"io"
Expand All @@ -18,7 +18,6 @@ import (
"path/filepath"
"sync"

"github.com/pkg/errors"
"google.golang.org/protobuf/proto"

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

var (
errBadMagic = stderrors.New("manifest has bad magic")
errBadChecksum = stderrors.New("manifest has checksum mismatch")
errBadMagic = errors.New("manifest has bad magic")
errBadChecksum = errors.New("manifest has checksum mismatch")
)

// ReplayManifestFile reads the manifest file and constructs two manifest objects. (We need one
Expand Down Expand Up @@ -399,7 +398,7 @@ func ReplayManifestFile(fp *os.File, extMagic uint16) (Manifest, int64, error) {
length := y.BytesToU32(lenCrcBuf[0:4])
// Sanity check to ensure we don't over-allocate memory.
if length > uint32(stat.Size()) {
return Manifest{}, 0, errors.Errorf(
return Manifest{}, 0, fmt.Errorf(
"Buffer length: %d greater than file size: %d. Manifest file might be corrupted",
length, stat.Size())
}
Expand Down
4 changes: 1 addition & 3 deletions memtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"sync"
"sync/atomic"

"github.com/pkg/errors"

"github.com/dgraph-io/badger/v4/pb"
"github.com/dgraph-io/badger/v4/skl"
"github.com/dgraph-io/badger/v4/y"
Expand Down Expand Up @@ -147,7 +145,7 @@ func (db *DB) newMemTable() (*memTable, error) {
db.opt.Errorf("Got error: %v for id: %d\n", err, db.nextMemFid)
return nil, y.Wrapf(err, "newMemTable")
}
return nil, errors.Errorf("File %s already exists", mt.wal.Fd.Name())
return nil, fmt.Errorf("File %s already exists", mt.wal.Fd.Name())
}

func (db *DB) mtFilePath(fid int) string {
Expand Down
8 changes: 3 additions & 5 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"strings"
"time"

"github.com/pkg/errors"

"github.com/dgraph-io/badger/v4/options"
"github.com/dgraph-io/badger/v4/table"
"github.com/dgraph-io/badger/v4/y"
Expand Down Expand Up @@ -234,10 +232,10 @@ func parseCompression(cStr string) (options.CompressionType, int, error) {
y.Check(err)
if level <= 0 {
return 0, 0,
errors.Errorf("ERROR: compression level(%v) must be greater than zero", level)
fmt.Errorf("ERROR: compression level(%v) must be greater than zero", level)
}
} else if len(cStrSplit) > 2 {
return 0, 0, errors.Errorf("ERROR: Invalid badger.compression argument")
return 0, 0, fmt.Errorf("ERROR: Invalid badger.compression argument")
}
switch cType {
case "zstd":
Expand All @@ -247,7 +245,7 @@ func parseCompression(cStr string) (options.CompressionType, int, error) {
case "none":
return options.None, 0, nil
}
return 0, 0, errors.Errorf("ERROR: compression type (%s) invalid", cType)
return 0, 0, fmt.Errorf("ERROR: compression type (%s) invalid", cType)
}

// generateSuperFlag generates an identical SuperFlag string from the provided Options.
Expand Down
2 changes: 1 addition & 1 deletion publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ package badger

import (
"context"
"errors"
"fmt"
"runtime"
"sync"
"sync/atomic"
"testing"

"github.com/pkg/errors"
"github.com/stretchr/testify/require"

"github.com/dgraph-io/badger/v4/pb"
Expand Down
Loading