8000 chore: remove github.com/pkg/errors dependency by thejedimasterbr · Pull Request #443 · hypermodeinc/ristretto · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore: remove github.com/pkg/errors dependency #443

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
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
8000
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ adhere to [Semantic Versioning](http://semver.org/spec/v2.0.0.html) starting v1.

## [Unreleased]

**Changed**

- Remove dependency: github.com/pkg/errors (#443)

**Fixed**

- Switch from using a sync.Waitgroup, to closing a channel of struct{} (#442)
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/cespare/xxhash/v2 v2.3.0
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da
github.com/dustin/go-humanize v1.0.1
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.10.0
golang.org/x/sys v0.30.0
)
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da h1:aIftn67I1fkbMa5
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da/go.mod h1:SqUrOPUns 10000 FjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
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/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/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
Expand Down
13 changes: 6 additions & 7 deletions z/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ package z

import (
"encoding/binary"
"errors"
"fmt"
"log"
"os"
"sort"
"sync/atomic"

"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -212,8 +211,8 @@ func (b *Buffer) Grow(n int) {
case UseMmap:
// Truncate and remap the underlying file.
if err := b.mmapFile.Truncate(int64(b.curSz)); err != nil {
err = errors.Wrapf(err,
"while trying to truncate file: %s to size: %d", b.mmapFile.Fd.Name(), b.curSz)
err = errors.Join(err,
fmt.Errorf("while trying to truncate file: %s to size: %d", b.mmapFile.Fd.Name(), b.curSz))
panic(err)
}
b.buf = b.mmapFile.Data
Expand Down Expand Up @@ -337,7 +336,7 @@ func (s *sortHelper) sortSmall(start, end int) {

func assert(b bool) {
if !b {
log.Fatalf("%+v", errors.Errorf("Assertion failure"))
log.Fatalf("%+v", errors.New("Assertion failure"))
}
}
func check(err error) {
Expand Down Expand Up @@ -523,11 +522,11 @@ func (b *Buffer) Release() error {
}
path := b.mmapFile.Fd.Name()
if err := b.mmapFile.Close(-1); err != nil {
return errors.Wrapf(err, "while closing file: %s", path)
return errors.Join(err, fmt.Errorf("while closing file: %s", path))
}
if !b.persistent {
if err := os.Remove(path); err != nil {
return errors.Wrapf(err, "while deleting file %s", path)
return errors.Join(err, fmt.Errorf("while deleting file %s", path))
}
}
}
Expand Down
17 changes: 8 additions & 9 deletions z/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ package z

import (
"encoding/binary"
"errors"
"fmt"
"io"
"os"
"path/filepath"

"github.com/pkg/errors"
)

// MmapFile represents an mmapd file and includes both the buffer to the data
Expand All @@ -28,15 +27,15 @@ func OpenMmapFileUsing(fd *os.File, sz int, writable bool) (*MmapFile, error) {
filename := fd.Name()
fi, err := fd.Stat()
if err != nil {
return nil, errors.Wrapf(err, "cannot stat file: %s", filename)
return nil, errors.Join(err, fmt.Errorf("cannot stat file: %s", filename))
}

var rerr error
fileSize := fi.Size()
if sz > 0 && fileSize == 0 {
// If file is empty, truncate it to sz.
if err := fd.Truncate(int64(sz)); err != nil {
return nil, errors.Wrapf(err, "error while truncation")
return nil, errors.Join(err, errors.New("error while truncation"))
}
fileSize = int64(sz)
rerr = NewFile
Expand All @@ -45,7 +44,7 @@ func OpenMmapFileUsing(fd *os.File, sz int, writable bool) (*MmapFile, error) {
// fmt.Printf("Mmaping file: %s with writable: %v filesize: %d\n", fd.Name(), writable, fileSize)
buf, err := Mmap(fd, writable, fileSize) // Mmap up to file size.
if err != nil {
return nil, errors.Wrapf(err, "while mmapping %s with size: %d", fd.Name(), fileSize)
return nil, errors.Join(err, fmt.Errorf("while mmapping %s with size: %d", fd.Name(), fileSize))
}

if fileSize == 0 {
Expand All @@ -68,7 +67,7 @@ func OpenMmapFile(filename string, flag int, maxSz int) (*MmapFile, error) {
// fmt.Printf("opening file %s with flag: %v\n", filename, flag)
fd, err := os.OpenFile(filename, flag, 0666)
if err != nil {
return nil, errors.Wrapf(err, "unable to open: %s", filename)
return nil, errors.Join(err, fmt.Errorf("unable to open: %s", filename))
}
writable := true
if flag == os.O_RDONLY {
Expand Down Expand Up @@ -196,13 +195,13 @@ func (m *MmapFile) Close(maxSz int64) error {
func SyncDir(dir string) error {
df, err := os.Open(dir)
if err != nil {
return errors.Wrapf(err, "while opening %s", dir)
return errors.Join(err, fmt.Errorf("while opening %s", dir))
}
if err := df.Sync(); err != nil {
return errors.Wrapf(err, "while syncing %s", dir)
return errors.Join(err, fmt.Errorf("while syncing %s", dir))
}
if err := df.Close(); err != nil {
return errors.Wrapf(err, "while closing %s", dir)
return errors.Join(err, fmt.Errorf("while closing %s", dir))
}
return nil
}
32 changes: 13 additions & 19 deletions z/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package z

import (
"errors"
"fmt"
"log"
"os"
Expand All @@ -15,8 +16,6 @@ import (
"strconv"
"strings"
"time"

"github.com/pkg/errors"
)

// SuperFlagHelp makes it really easy to generate command line `--help` output for a SuperFlag. For
9E81 Expand Down Expand Up @@ -209,9 +208,8 @@ func (sf *SuperFlag) GetBool(opt string) bool {
}
b, err := strconv.ParseBool(val)
if err != nil {
err = errors.Wrapf(err,
"Unable to parse %s as bool for key: %s. Options: %s\n",
val, opt, sf)
err = errors.Join(err,
fmt.Errorf("Unable to parse %s as bool for key: %s. Options: %s\n", val, opt, sf))
log.Fatalf("%+v", err)
}
return b
Expand All @@ -224,9 +222,8 @@ func (sf *SuperFlag) GetFloat64(opt string) float64 {
}
f, err := strconv.ParseFloat(val, 64)
if err != nil {
err = errors.Wrapf(err,
"Unable to parse %s as float64 for key: %s. Options: %s\n",
val, opt, sf)
err = errors.Join(err,
fmt.Errorf("Unable to parse %s as float64 for key: %s. Options: %s\n", val, opt, sf))
log.Fatalf("%+v", err)
}
return f
Expand All @@ -239,9 +236,8 @@ func (sf *SuperFlag) GetInt64(opt string) int64 {
}
i, err := strconv.ParseInt(val, 0, 64)
if err != nil {
err = errors.Wrapf(err,
"Unable to parse %s as int64 for key: %s. Options: %s\n",
val, opt, sf)
err = errors.Join(err,
fmt.Errorf("Unable to parse %s as int64 for key: %s. Options: %s\n", val, opt, sf))
log.Fatalf("%+v", err)
}
return i
Expand All @@ -254,9 +250,8 @@ func (sf *SuperFlag) GetUint64(opt string) uint64 {
}
u, err := strconv.ParseUint(val, 0, 64)
if err != nil {
err = errors.Wrapf(err,
"Unable to parse %s as uint64 for key: %s. Options: %s\n",
val, opt, sf)
err = errors.Join(err,
fmt.Errorf("Unable to parse %s as uint64 for key: %s. Options: %s\n", val, opt, sf))
log.Fatalf("%+v", err)
}
return u
Expand All @@ -269,9 +264,8 @@ func (sf *SuperFlag) GetUint32(opt string) uint32 {
}
u, err := strconv.ParseUint(val, 0, 32)
if err != nil {
err = errors.Wrapf(err,
"Unable to parse %s as uint32 for key: %s. Options: %s\n",
val, opt, sf)
err = errors.Join(err,
fmt.Errorf("Unable to parse %s as uint32 for key: %s. Options: %s\n", val, opt, sf))
log.Fatalf("%+v", err)
}
return uint32(u)
Expand Down Expand Up @@ -302,15 +296,15 @@ func expandPath(path string) (string, error) {
if path[0] == '~' && (len(path) == 1 || os.IsPathSeparator(path[1])) {
usr, err := user.Current()
if err != nil {
return "", errors.Wrap(err, "Failed to get the home directory of the user")
return "", errors.Join(err, errors.New("Failed to get the home directory of the user"))
}
path = filepath.Join(usr.HomeDir, path[1:])
}

var err error
path, err = filepath.Abs(path)
if err != nil {
return "", errors.Wrap(err, "Failed to generate absolute path")
return "", errors.Join(err, errors.New("Failed to generate absolute path"))
}
return path, nil
}
Loading
0