Skip to content

Commit 13b83e4

Browse files
fix(rclone/operations): remove misleading permission error from CheckPermissions
Assuming that every error is permission error is wrong and misleading. Fixes #3738
1 parent dae70b2 commit 13b83e4

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

pkg/rclone/operations/operations.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ import (
1717
"github.com/rclone/rclone/lib/pacer"
1818
)
1919

20-
// PermissionError wraps remote fs errors returned by CheckPermissions function
20+
// OperationError wraps remote fs errors returned by CheckPermissions function
2121
// and allows to set a custom message returned to user.
22-
type PermissionError struct {
22+
type OperationError struct {
2323
cause error
2424
op string
2525
statusCode int
2626
}
2727

28-
func asPermissionError(op string, l fs.Fs, err error) PermissionError {
28+
func asOperationError(op string, l fs.Fs, err error) OperationError {
2929
statusCode := 400
3030

3131
if l.Name() == "s3" {
@@ -37,23 +37,23 @@ func asPermissionError(op string, l fs.Fs, err error) PermissionError {
3737
}
3838
}
3939

40-
return PermissionError{
40+
return OperationError{
4141
cause: err,
4242
op: op,
4343
statusCode: statusCode,
4444
}
4545
}
4646

47-
func (e PermissionError) Error() string {
48-
return "no " + e.op + " permission" + ": " + e.cause.Error()
47+
func (e OperationError) Error() string {
48+
return "operation " + e.op + ": " + e.cause.Error()
4949
}
5050

51-
func (e PermissionError) String() string {
51+
func (e OperationError) String() string {
5252
return e.Error()
5353
}
5454

5555
// StatusCode returns HTTP status code that should be returned for this error.
56-
func (e PermissionError) StatusCode() int {
56+
func (e OperationError) StatusCode() int {
5757
return e.statusCode
5858
}
5959

@@ -94,7 +94,7 @@ func CheckPermissions(ctx context.Context, l fs.Fs) error {
9494
if errors.Is(err, credentials.ErrNoValidProvidersFoundInChain) {
9595
return errors.New("no providers - attach IAM Role to EC2 instance or put your access keys to s3 section of /etc/scylla-manager-agent/scylla-manager-agent.yaml and restart agent") // nolint: lll
9696
}
97-
return asPermissionError("put", l, err)
97+
return asOperationError("put", l, err)
9898
}
9999
}
100100

@@ -107,7 +107,7 @@ func CheckPermissions(ctx context.Context, l fs.Fs) error {
107107
if err := operations.ListJSON(ctx, l, testDirName, &opts, func(item *operations.ListJSONItem) error {
108108
return nil
109109
}); err != nil {
110-
return asPermissionError("list", l, err)
110+
return asOperationError("list", l, err)
111111
}
112112
}
113113

@@ -119,11 +119,11 @@ func CheckPermissions(ctx context.Context, l fs.Fs) error {
119119
}
120120
r, err := o.Open(ctx)
121121
if err != nil {
122-
return asPermissionError("open", l, err)
122+
return asOperationError("open", l, err)
123123
}
124124
defer r.Close()
125125
if _, err := io.Copy(io.Discard, r); err != nil {
126-
return asPermissionError("copy", l, err)
126+
return asOperationError("copy", l, err)
127127
}
128128
}
129129

@@ -134,7 +134,7 @@ func CheckPermissions(ctx context.Context, l fs.Fs) error {
134134
return errors.Wrap(err, "init remote temp dir")
135135
}
136136
if err := operations.Delete(ctx, f); err != nil {
137-
return asPermissionError("delete", l, err)
137+
return asOperationError("delete", l, err)
138138
}
139139
}
140140

pkg/rclone/rcserver/rcserver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (s Server) writeError(path string, in rc.Params, w http.ResponseWriter, err
8080

8181
fs.Errorf(nil, "rc: %q: error: %v", path, err)
8282
// Adjust the error return for some well known errors
83-
if e, ok := err.(operations.PermissionError); ok { // nolint: errorlint
83+
if e, ok := err.(operations.OperationError); ok { // nolint: errorlint
8484
status = e.StatusCode()
8585
} else {
8686
switch {

0 commit comments

Comments
 (0)