Remove github.com/pkg/errors and replace with std library version

This is possible now that we no longer support go1.12 and brings
rclone into line with standard practices in the Go world.

This also removes errors.New and errors.Errorf from lib/errors and
prefers the stdlib errors package over lib/errors.
This commit is contained in:
Nick Craig-Wood committed 2021-11-07 11:53:30 +00:00
1 parent 97328e5755
commit e43b5ce5e5
233 files changed
+1673 -1695

No files matched your search

+7 -7
View File
@@ -3,6 +3,7 @@ package docker
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"os"
@@ -13,7 +14,6 @@ import (
"time"
sysdnotify "github.com/iguanesolutions/go-systemd/v5/notify"
"github.com/pkg/errors"
"github.com/rclone/rclone/cmd/mountlib"
"github.com/rclone/rclone/fs"
@@ -44,12 +44,12 @@ func NewDriver(ctx context.Context, root string, mntOpt *mountlib.Options, vfsOp
cacheDir := config.GetCacheDir()
err := file.MkdirAll(cacheDir, 0700)
if err != nil {
return nil, errors.Wrapf(err, "failed to create cache directory: %s", cacheDir)
return nil, fmt.Errorf("failed to create cache directory: %s: %w", cacheDir, err)
}
//err = file.MkdirAll(root, 0755)
if err != nil {
return nil, errors.Wrapf(err, "failed to create mount root: %s", root)
return nil, fmt.Errorf("failed to create mount root: %s: %w", root, err)
}
// setup driver state
@@ -72,7 +72,7 @@ func NewDriver(ctx context.Context, root string, mntOpt *mountlib.Options, vfsOp
// restore from saved state
if !forgetState {
if err = drv.restoreState(ctx); err != nil {
return nil, errors.Wrap(err, "failed to restore state")
return nil, fmt.Errorf("failed to restore state: %w", err)
}
}
@@ -89,7 +89,7 @@ func NewDriver(ctx context.Context, root string, mntOpt *mountlib.Options, vfsOp
// notify systemd
if err := sysdnotify.Ready(); err != nil {
return nil, errors.Wrap(err, "failed to notify systemd")
return nil, fmt.Errorf("failed to notify systemd: %w", err)
}
return drv, nil
@@ -323,7 +323,7 @@ func (drv *Driver) saveState() error {
data, err := json.Marshal(state)
if err != nil {
return errors.Wrap(err, "failed to marshal state")
return fmt.Errorf("failed to marshal state: %w", err)
}
ctx := context.Background()
@@ -335,7 +335,7 @@ func (drv *Driver) saveState() error {
}
time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
}
return errors.Wrap(err, "failed to save state")
return fmt.Errorf("failed to save state: %w", err)
}
// restoreState recreates volumes from saved driver state
+8 -8
View File
@@ -1,6 +1,7 @@
package docker
import (
"fmt"
"strconv"
"strings"
@@ -12,7 +13,6 @@ import (
"github.com/rclone/rclone/vfs/vfscommon"
"github.com/rclone/rclone/vfs/vfsflags"
"github.com/pkg/errors"
"github.com/spf13/pflag"
)
@@ -62,7 +62,7 @@ func (vol *Volume) applyOptions(volOpt VolOpts) error {
case "remote", "fs":
p, err := fspath.Parse(str)
if err != nil || p.Name == ":" {
return errors.Wrapf(err, "cannot parse path %q", str)
return fmt.Errorf("cannot parse path %q: %w", str, err)
}
fsName, fsPath, fsOpt = p.Name, p.Path, p.Config
vol.Fs = str
@@ -100,7 +100,7 @@ func (vol *Volume) applyOptions(volOpt VolOpts) error {
}
fsInfo, err := fs.Find(fsType)
if err != nil {
return errors.Errorf("unknown filesystem type %q", fsType)
return fmt.Errorf("unknown filesystem type %q", fsType)
}
// handle remaining options, override fsOpt
@@ -124,21 +124,21 @@ func (vol *Volume) applyOptions(volOpt VolOpts) error {
ok = true
}
if err != nil {
return errors.Wrapf(err, "cannot parse option %q", key)
return fmt.Errorf("cannot parse option %q: %w", key, err)
}
if !ok {
// try to use as a mount option in mntOpt
ok, err = getMountOption(mntOpt, opt, key)
if ok && err != nil {
return errors.Wrapf(err, "cannot parse mount option %q", key)
return fmt.Errorf("cannot parse mount option %q: %w", key, err)
}
}
if !ok {
// try as a vfs option in vfsOpt
ok, err = getVFSOption(vfsOpt, opt, key)
if ok && err != nil {
return errors.Wrapf(err, "cannot parse vfs option %q", key)
return fmt.Errorf("cannot parse vfs option %q: %w", key, err)
}
}
@@ -149,11 +149,11 @@ func (vol *Volume) applyOptions(volOpt VolOpts) error {
hasFsPrefix := optWithPrefix != fsOptName
if !hasFsPrefix || fsInfo.Options.Get(fsOptName) == nil {
fs.Logf(nil, "Option %q is not supported by backend %q", key, fsType)
return errors.Errorf("unsupported backend option %q", key)
return fmt.Errorf("unsupported backend option %q", key)
}
fsOpt[fsOptName], err = opt.GetString(key)
if err != nil {
return errors.Wrapf(err, "cannot parse backend option %q", key)
return fmt.Errorf("cannot parse backend option %q: %w", key, err)
}
}
}
+5 -5
View File
@@ -2,14 +2,14 @@ package docker
import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"runtime"
"sort"
"time"
"github.com/pkg/errors"
"github.com/rclone/rclone/cmd/mountlib"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/config"
@@ -155,7 +155,7 @@ func (vol *Volume) checkMountpoint() error {
_, err := os.Lstat(path)
if os.IsNotExist(err) {
if err = file.MkdirAll(path, 0700); err != nil {
return errors.Wrapf(err, "failed to create mountpoint: %s", path)
return fmt.Errorf("failed to create mountpoint: %s: %w", path, err)
}
} else if err != nil {
return err
@@ -182,7 +182,7 @@ func (vol *Volume) setup(ctx context.Context) error {
_, mountFn := mountlib.ResolveMountMethod(vol.mountType)
if mountFn == nil {
if vol.mountType != "" {
return errors.Errorf("unsupported mount type %q", vol.mountType)
return fmt.Errorf("unsupported mount type %q", vol.mountType)
}
return errors.New("mount command unsupported by this build")
}
@@ -242,7 +242,7 @@ func (vol *Volume) clearCache() error {
}
root, err := VFS.Root()
if err != nil {
return errors.Wrapf(err, "error reading root: %v", VFS.Fs())
return fmt.Errorf("error reading root: %v: %w", VFS.Fs(), err)
}
root.ForgetAll()
return nil