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:
@@ -18,6 +18,7 @@ canStream = false
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
@@ -27,7 +28,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rclone/rclone/backend/premiumizeme/api"
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/config"
|
||||
@@ -250,7 +250,7 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
|
||||
if opt.APIKey == "" {
|
||||
client, ts, err = oauthutil.NewClient(ctx, name, m, oauthConfig)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to configure premiumize.me")
|
||||
return nil, fmt.Errorf("failed to configure premiumize.me: %w", err)
|
||||
}
|
||||
} else {
|
||||
client = fshttp.NewClient(ctx)
|
||||
@@ -380,10 +380,10 @@ func (f *Fs) CreateDir(ctx context.Context, pathID, leaf string) (newID string,
|
||||
})
|
||||
if err != nil {
|
||||
//fmt.Printf("...Error %v\n", err)
|
||||
return "", errors.Wrap(err, "CreateDir http")
|
||||
return "", fmt.Errorf("CreateDir http: %w", err)
|
||||
}
|
||||
if err = info.AsErr(); err != nil {
|
||||
return "", errors.Wrap(err, "CreateDir")
|
||||
return "", fmt.Errorf("CreateDir: %w", err)
|
||||
}
|
||||
// fmt.Printf("...Id %q\n", *info.Id)
|
||||
return info.ID, nil
|
||||
@@ -420,10 +420,10 @@ func (f *Fs) listAll(ctx context.Context, dirID string, directoriesOnly bool, fi
|
||||
return shouldRetry(ctx, resp, err)
|
||||
})
|
||||
if err != nil {
|
||||
return newDirID, found, errors.Wrap(err, "couldn't list files")
|
||||
return newDirID, found, fmt.Errorf("couldn't list files: %w", err)
|
||||
}
|
||||
if err = result.AsErr(); err != nil {
|
||||
return newDirID, found, errors.Wrap(err, "error while listing")
|
||||
return newDirID, found, fmt.Errorf("error while listing: %w", err)
|
||||
}
|
||||
newDirID = result.FolderID
|
||||
for i := range result.Content {
|
||||
@@ -572,7 +572,7 @@ func (f *Fs) purgeCheck(ctx context.Context, dir string, check bool) error {
|
||||
return true
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "purgeCheck")
|
||||
return fmt.Errorf("purgeCheck: %w", err)
|
||||
}
|
||||
if found {
|
||||
return fs.ErrorDirectoryNotEmpty
|
||||
@@ -594,10 +594,10 @@ func (f *Fs) purgeCheck(ctx context.Context, dir string, check bool) error {
|
||||
return shouldRetry(ctx, resp, err)
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "rmdir failed")
|
||||
return fmt.Errorf("rmdir failed: %w", err)
|
||||
}
|
||||
if err = result.AsErr(); err != nil {
|
||||
return errors.Wrap(err, "rmdir")
|
||||
return fmt.Errorf("rmdir: %w", err)
|
||||
}
|
||||
f.dirCache.FlushDir(dir)
|
||||
if err != nil {
|
||||
@@ -645,7 +645,7 @@ func (f *Fs) move(ctx context.Context, isFile bool, id, oldLeaf, newLeaf, oldDir
|
||||
tmpLeaf := newLeaf + "." + random.String(8)
|
||||
err = f.renameLeaf(ctx, isFile, id, tmpLeaf)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Move rename leaf")
|
||||
return fmt.Errorf("Move rename leaf: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -674,10 +674,10 @@ func (f *Fs) move(ctx context.Context, isFile bool, id, oldLeaf, newLeaf, oldDir
|
||||
return shouldRetry(ctx, resp, err)
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Move http")
|
||||
return fmt.Errorf("Move http: %w", err)
|
||||
}
|
||||
if err = result.AsErr(); err != nil {
|
||||
return errors.Wrap(err, "Move")
|
||||
return fmt.Errorf("Move: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,7 +685,7 @@ func (f *Fs) move(ctx context.Context, isFile bool, id, oldLeaf, newLeaf, oldDir
|
||||
if doRenameLeaf {
|
||||
err = f.renameLeaf(ctx, isFile, id, newLeaf)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Move rename leaf")
|
||||
return fmt.Errorf("Move rename leaf: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -783,10 +783,10 @@ func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) {
|
||||
return shouldRetry(ctx, resp, err)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CreateDir http")
|
||||
return nil, fmt.Errorf("CreateDir http: %w", err)
|
||||
}
|
||||
if err = info.AsErr(); err != nil {
|
||||
return nil, errors.Wrap(err, "CreateDir")
|
||||
return nil, fmt.Errorf("CreateDir: %w", err)
|
||||
}
|
||||
usage = &fs.Usage{
|
||||
Used: fs.NewUsageValue(int64(info.SpaceUsed)),
|
||||
@@ -843,7 +843,7 @@ func (o *Object) Size() int64 {
|
||||
// setMetaData sets the metadata from info
|
||||
func (o *Object) setMetaData(info *api.Item) (err error) {
|
||||
if info.Type != "file" {
|
||||
return errors.Wrapf(fs.ErrorNotAFile, "%q is %q", o.remote, info.Type)
|
||||
return fmt.Errorf("%q is %q: %w", o.remote, info.Type, fs.ErrorNotAFile)
|
||||
}
|
||||
o.hasMetaData = true
|
||||
o.size = info.Size
|
||||
@@ -953,19 +953,19 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
||||
var u *url.URL
|
||||
u, err = url.Parse(info.URL)
|
||||
if err != nil {
|
||||
return true, errors.Wrap(err, "failed to parse download URL")
|
||||
return true, fmt.Errorf("failed to parse download URL: %w", err)
|
||||
}
|
||||
_, err = net.LookupIP(u.Hostname())
|
||||
if err != nil {
|
||||
return true, errors.Wrap(err, "failed to resolve download URL")
|
||||
return true, fmt.Errorf("failed to resolve download URL: %w", err)
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "upload get URL http")
|
||||
return fmt.Errorf("upload get URL http: %w", err)
|
||||
}
|
||||
if err = info.AsErr(); err != nil {
|
||||
return errors.Wrap(err, "upload get URL")
|
||||
return fmt.Errorf("upload get URL: %w", err)
|
||||
}
|
||||
|
||||
// if file exists then rename it out the way otherwise uploads can fail
|
||||
@@ -976,7 +976,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
||||
fs.Debugf(o, "Moving old file out the way to %q", newLeaf)
|
||||
err = o.fs.renameLeaf(ctx, true, oldID, newLeaf)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "upload rename old file")
|
||||
return fmt.Errorf("upload rename old file: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
// on failed upload rename old file back
|
||||
@@ -984,7 +984,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
||||
fs.Debugf(o, "Renaming old file back (from %q to %q) since upload failed", leaf, newLeaf)
|
||||
newErr := o.fs.renameLeaf(ctx, true, oldID, leaf)
|
||||
if newErr != nil && err == nil {
|
||||
err = errors.Wrap(newErr, "upload renaming old file back")
|
||||
err = fmt.Errorf("upload renaming old file back: %w", newErr)
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -1007,10 +1007,10 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
||||
return shouldRetry(ctx, resp, err)
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "upload file http")
|
||||
return fmt.Errorf("upload file http: %w", err)
|
||||
}
|
||||
if err = result.AsErr(); err != nil {
|
||||
return errors.Wrap(err, "upload file")
|
||||
return fmt.Errorf("upload file: %w", err)
|
||||
}
|
||||
|
||||
// on successful upload, remove old file if it exists
|
||||
@@ -1019,7 +1019,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
||||
fs.Debugf(o, "Removing old file")
|
||||
err := o.fs.remove(ctx, oldID)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "upload remove old file")
|
||||
return fmt.Errorf("upload remove old file: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1049,10 +1049,10 @@ func (f *Fs) renameLeaf(ctx context.Context, isFile bool, id string, newLeaf str
|
||||
return shouldRetry(ctx, resp, err)
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "rename http")
|
||||
return fmt.Errorf("rename http: %w", err)
|
||||
}
|
||||
if err = result.AsErr(); err != nil {
|
||||
return errors.Wrap(err, "rename")
|
||||
return fmt.Errorf("rename: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1074,10 +1074,10 @@ func (f *Fs) remove(ctx context.Context, id string) (err error) {
|
||||
return shouldRetry(ctx, resp, err)
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "remove http")
|
||||
return fmt.Errorf("remove http: %w", err)
|
||||
}
|
||||
if err = result.AsErr(); err != nil {
|
||||
return errors.Wrap(err, "remove")
|
||||
return fmt.Errorf("remove: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1086,7 +1086,7 @@ func (f *Fs) remove(ctx context.Context, id string) (err error) {
|
||||
func (o *Object) Remove(ctx context.Context) error {
|
||||
err := o.readMetaData(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Remove: Failed to read metadata")
|
||||
return fmt.Errorf("Remove: Failed to read metadata: %w", err)
|
||||
}
|
||||
return o.fs.remove(ctx, o.id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user