mirror of
https://github.com/rclone/rclone.git
synced 2025-08-18 01:20:16 +02:00
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:
@@ -14,6 +14,7 @@ To work around this we use the remote "TestSugarSync:Test" to test with.
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -25,7 +26,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rclone/rclone/backend/sugarsync/api"
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/config"
|
||||
@@ -79,7 +79,7 @@ func init() {
|
||||
opt := new(Options)
|
||||
err := configstruct.Set(m, opt)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to read options")
|
||||
return nil, fmt.Errorf("failed to read options: %w", err)
|
||||
}
|
||||
|
||||
switch config.State {
|
||||
@@ -124,7 +124,7 @@ func init() {
|
||||
// return shouldRetry(ctx, resp, err)
|
||||
//})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get token")
|
||||
return nil, fmt.Errorf("failed to get token: %w", err)
|
||||
}
|
||||
opt.RefreshToken = resp.Header.Get("Location")
|
||||
m.Set("refresh_token", opt.RefreshToken)
|
||||
@@ -309,7 +309,7 @@ func (f *Fs) readMetaDataForID(ctx context.Context, ID string) (info *api.File,
|
||||
if resp != nil && resp.StatusCode == http.StatusNotFound {
|
||||
return nil, fs.ErrorObjectNotFound
|
||||
}
|
||||
return nil, errors.Wrap(err, "failed to get authorization")
|
||||
return nil, fmt.Errorf("failed to get authorization: %w", err)
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
@@ -343,7 +343,7 @@ func (f *Fs) getAuthToken(ctx context.Context) error {
|
||||
return shouldRetry(ctx, resp, err)
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get authorization")
|
||||
return fmt.Errorf("failed to get authorization: %w", err)
|
||||
}
|
||||
f.opt.Authorization = resp.Header.Get("Location")
|
||||
f.authExpiry = authResponse.Expiration
|
||||
@@ -391,7 +391,7 @@ func (f *Fs) getUser(ctx context.Context) (user *api.User, err error) {
|
||||
return shouldRetry(ctx, resp, err)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get user")
|
||||
return nil, fmt.Errorf("failed to get user: %w", err)
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
@@ -445,7 +445,7 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
|
||||
if strings.HasSuffix(f.opt.RootID, "/contents") {
|
||||
f.opt.RootID = f.opt.RootID[:len(f.opt.RootID)-9]
|
||||
} else {
|
||||
return nil, errors.Errorf("unexpected rootID %q", f.opt.RootID)
|
||||
return nil, fmt.Errorf("unexpected rootID %q", f.opt.RootID)
|
||||
}
|
||||
// Cache the results
|
||||
f.m.Set("root_id", f.opt.RootID)
|
||||
@@ -497,13 +497,13 @@ var findError = regexp.MustCompile(`<h3>(.*?)</h3>`)
|
||||
func errorHandler(resp *http.Response) (err error) {
|
||||
body, err := rest.ReadBody(resp)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error reading error out of body")
|
||||
return fmt.Errorf("error reading error out of body: %w", err)
|
||||
}
|
||||
match := findError.FindSubmatch(body)
|
||||
if match == nil || len(match) < 2 || len(match[1]) == 0 {
|
||||
return errors.Errorf("HTTP error %v (%v) returned body: %q", resp.StatusCode, resp.Status, body)
|
||||
return fmt.Errorf("HTTP error %v (%v) returned body: %q", resp.StatusCode, resp.Status, body)
|
||||
}
|
||||
return errors.Errorf("HTTP error %v (%v): %s", resp.StatusCode, resp.Status, match[1])
|
||||
return fmt.Errorf("HTTP error %v (%v): %s", resp.StatusCode, resp.Status, match[1])
|
||||
}
|
||||
|
||||
// rootSlash returns root with a slash on if it is empty, otherwise empty string
|
||||
@@ -596,7 +596,7 @@ func (f *Fs) CreateDir(ctx context.Context, pathID, leaf string) (newID string,
|
||||
return "", err
|
||||
}
|
||||
if !found {
|
||||
return "", errors.Errorf("couldn't find ID for newly created directory %q", leaf)
|
||||
return "", fmt.Errorf("couldn't find ID for newly created directory %q", leaf)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -636,7 +636,7 @@ OUTER:
|
||||
return shouldRetry(ctx, resp, err)
|
||||
})
|
||||
if err != nil {
|
||||
return found, errors.Wrap(err, "couldn't list files")
|
||||
return found, fmt.Errorf("couldn't list files: %w", err)
|
||||
}
|
||||
if fileFn != nil {
|
||||
for i := range result.Files {
|
||||
@@ -873,7 +873,7 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
||||
srcPath := srcObj.fs.rootSlash() + srcObj.remote
|
||||
dstPath := f.rootSlash() + remote
|
||||
if strings.ToLower(srcPath) == strings.ToLower(dstPath) {
|
||||
return nil, errors.Errorf("can't copy %q -> %q as are same name when lowercase", srcPath, dstPath)
|
||||
return nil, fmt.Errorf("can't copy %q -> %q as are same name when lowercase", srcPath, dstPath)
|
||||
}
|
||||
|
||||
// Create temporary object
|
||||
@@ -1247,7 +1247,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
||||
if o.id == "" {
|
||||
o.id, err = o.fs.createFile(ctx, directoryID, leaf, fs.MimeType(ctx, src))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create file")
|
||||
return fmt.Errorf("failed to create file: %w", err)
|
||||
}
|
||||
if o.id == "" {
|
||||
return errors.New("failed to create file: no ID")
|
||||
@@ -1280,7 +1280,7 @@ 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, "failed to upload file")
|
||||
return fmt.Errorf("failed to upload file: %w", err)
|
||||
}
|
||||
|
||||
o.hasMetaData = false
|
||||
|
Reference in New Issue
Block a user