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:
parent
97328e5755
commit
e43b5ce5e5
233 changed files with 1673 additions and 1695 deletions
|
@ -10,12 +10,13 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"syscall/js"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/rc"
|
||||
|
||||
|
@ -54,10 +55,9 @@ func paramToValue(in rc.Params) (out js.Value) {
|
|||
func errorValue(method string, in js.Value, err error) js.Value {
|
||||
fs.Errorf(nil, "rc: %q: error: %v", method, err)
|
||||
// Adjust the error return for some well known errors
|
||||
errOrig := errors.Cause(err)
|
||||
status := http.StatusInternalServerError
|
||||
switch {
|
||||
case errOrig == fs.ErrorDirNotFound || errOrig == fs.ErrorObjectNotFound:
|
||||
case errors.Is(err, fs.ErrorDirNotFound) || errors.Is(err, fs.ErrorObjectNotFound):
|
||||
status = http.StatusNotFound
|
||||
case rc.IsErrParamInvalid(err) || rc.IsErrParamNotFound(err):
|
||||
status = http.StatusBadRequest
|
||||
|
@ -89,7 +89,7 @@ func rcCallback(this js.Value, args []js.Value) interface{} {
|
|||
inJSON := jsJSON.Call("stringify", inRaw).String()
|
||||
err := json.Unmarshal([]byte(inJSON), &in)
|
||||
if err != nil {
|
||||
return errorValue(method, inRaw, errors.Wrap(err, "couldn't unmarshal input"))
|
||||
return errorValue(method, inRaw, fmt.Errorf("couldn't unmarshal input: %w", err))
|
||||
}
|
||||
default:
|
||||
return errorValue(method, inRaw, errors.New("in parameter must be null or object"))
|
||||
|
@ -97,12 +97,12 @@ func rcCallback(this js.Value, args []js.Value) interface{} {
|
|||
|
||||
call := rc.Calls.Get(method)
|
||||
if call == nil {
|
||||
return errorValue(method, inRaw, errors.Errorf("method %q not found", method))
|
||||
return errorValue(method, inRaw, fmt.Errorf("method %q not found", method))
|
||||
}
|
||||
|
||||
out, err := call.Fn(ctx, in)
|
||||
if err != nil {
|
||||
return errorValue(method, inRaw, errors.Wrap(err, "method call failed"))
|
||||
return errorValue(method, inRaw, fmt.Errorf("method call failed: %w", err))
|
||||
}
|
||||
if out == nil {
|
||||
return nil
|
||||
|
@ -110,7 +110,7 @@ func rcCallback(this js.Value, args []js.Value) interface{} {
|
|||
var out2 map[string]interface{}
|
||||
err = rc.Reshape(&out2, out)
|
||||
if err != nil {
|
||||
return errorValue(method, inRaw, errors.Wrap(err, "result reshape failed"))
|
||||
return errorValue(method, inRaw, fmt.Errorf("result reshape failed: %w", err))
|
||||
}
|
||||
|
||||
return js.ValueOf(out2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue