Skip to content

Commit

Permalink
WebClient: improve error message when trying to move non-empty folder
Browse files Browse the repository at this point in the history
Signed-off-by: Nicola Murino <[email protected]>
  • Loading branch information
drakkan committed Feb 18, 2024
1 parent 5a319dc commit d92f85d
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
6 changes: 3 additions & 3 deletions internal/common/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1728,9 +1728,9 @@ func (c *BaseConnection) GetGenericError(err error) error {
}
return sftp.ErrSSHFxFailure
default:
if err == ErrPermissionDenied || err == ErrNotExist || err == ErrOpUnsupported ||
err == ErrQuotaExceeded || err == ErrReadQuotaExceeded || err == vfs.ErrStorageSizeUnavailable ||
err == ErrShuttingDown {
if errors.Is(err, ErrPermissionDenied) || errors.Is(err, ErrNotExist) || errors.Is(err, ErrOpUnsupported) ||
errors.Is(err, ErrQuotaExceeded) || errors.Is(err, ErrReadQuotaExceeded) ||
errors.Is(err, vfs.ErrStorageSizeUnavailable) || errors.Is(err, ErrShuttingDown) {
return err
}
c.Log(logger.LevelError, "generic error: %+v", err)
Expand Down
4 changes: 2 additions & 2 deletions internal/vfs/azblobfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ func (*AzureBlobFs) IsNotSupported(err error) bool {
if err == nil {
return false
}
return err == ErrVfsUnsupported
return errors.Is(err, ErrVfsUnsupported)
}

func (*AzureBlobFs) isBadRequestError(err error) bool {
Expand Down Expand Up @@ -782,7 +782,7 @@ func (fs *AzureBlobFs) renameInternal(source, target string, fi os.FileInfo, rec
return numFiles, filesSize, err
}
if hasContents {
return numFiles, filesSize, fmt.Errorf("cannot rename non empty directory: %q", source)
return numFiles, filesSize, fmt.Errorf("%w: cannot rename non empty directory: %q", ErrVfsUnsupported, source)
}
}
if err := fs.mkdirInternal(target); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions internal/vfs/gcsfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package vfs

import (
"context"
"errors"
"fmt"
"io"
"mime"
Expand Down Expand Up @@ -448,7 +449,7 @@ func (*GCSFs) IsNotSupported(err error) bool {
if err == nil {
return false
}
return err == ErrVfsUnsupported
return errors.Is(err, ErrVfsUnsupported)
}

// CheckRootPath creates the specified local root directory if it does not exists
Expand Down Expand Up @@ -774,7 +775,7 @@ func (fs *GCSFs) renameInternal(source, target string, fi os.FileInfo, recursion
return numFiles, filesSize, err
}
if hasContents {
return numFiles, filesSize, fmt.Errorf("cannot rename non empty directory: %q", source)
return numFiles, filesSize, fmt.Errorf("%w: cannot rename non empty directory: %q", ErrVfsUnsupported, source)
}
}
if err := fs.mkdirInternal(target); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/vfs/s3fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ func (*S3Fs) IsNotSupported(err error) bool {
if err == nil {
return false
}
return err == ErrVfsUnsupported
return errors.Is(err, ErrVfsUnsupported)
}

// CheckRootPath creates the specified local root directory if it does not exists
Expand Down Expand Up @@ -700,7 +700,7 @@ func (fs *S3Fs) renameInternal(source, target string, fi os.FileInfo, recursion
return numFiles, filesSize, err
}
if hasContents {
return numFiles, filesSize, fmt.Errorf("cannot rename non empty directory: %q", source)
return numFiles, filesSize, fmt.Errorf("%w: cannot rename non empty directory: %q", ErrVfsUnsupported, source)
}
}
if err := fs.mkdirInternal(target); err != nil {
Expand Down
6 changes: 4 additions & 2 deletions static/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,17 @@
"err_generic": "Error moving files/directories",
"err_403": "$t(fs.move.err_generic). $t(fs.err_403)",
"err_429": "$t(fs.move.err_generic). $t(fs.err_429)",
"err_exists": "$t(fs.move.err_generic). $t(fs.err_exists)"
"err_exists": "$t(fs.move.err_generic). $t(fs.err_exists)",
"err_unsupported": "Unsupported: if you want to move a directory make sure it is empty"
},
"rename": {
"title": "Rename \"{{- name}}\"",
"new_name": "New name",
"err_generic": "Unable to rename \"{{- name}}\"",
"err_403": "$t(fs.rename.err_generic). $t(fs.err_403)",
"err_429": "$t(fs.rename.err_generic). $t(fs.err_429)",
"err_exists": "$t(fs.rename.err_generic). $t(fs.err_exists)"
"err_exists": "$t(fs.rename.err_generic). $t(fs.err_exists)",
"err_unsupported": "Unsupported: if you want to rename a directory make sure it is empty"
},
"upload": {
"text": "Upload Files",
Expand Down
6 changes: 4 additions & 2 deletions static/locales/it/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,17 @@
"err_generic": "Errore nello spostamento di file/directory",
"err_403": "$t(fs.move.err_generic). $t(fs.err_403)",
"err_429": "$t(fs.move.err_generic). $t(fs.err_429)",
"err_exists": "$t(fs.move.err_generic). $t(fs.err_exists)"
"err_exists": "$t(fs.move.err_generic). $t(fs.err_exists)",
"err_unsupported": "Non supportato: se vuoi spostare una directory assicurati che sia vuota"
},
"rename": {
"title": "Rinomina \"{{- name}}\"",
"new_name": "Nuovo nome",
"err_generic": "Impossibile rinominare \"{{- name}}\"",
"err_403": "$t(fs.rename.err_generic): $t(fs.err_403)",
"err_429": "$t(fs.rename.err_generic): $t(fs.err_429)",
"err_exists": "$t(fs.rename.err_generic). $t(fs.err_exists)"
"err_exists": "$t(fs.rename.err_generic). $t(fs.err_exists)",
"err_unsupported": "Non supportato: se vuoi rinominare una directory assicurati che sia vuota"
},
"upload": {
"text": "Carica file",
Expand Down
6 changes: 6 additions & 0 deletions templates/webclient/files.html
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,9 @@ <h4 class="gslide-title"></h4>
let errorMessage = "";
if (error && error.response) {
switch (error.response.status) {
case 400:
errorMessage = "fs.move.err_unsupported";
break;
case 403:
errorMessage = "fs.move.err_403";
break;
Expand Down Expand Up @@ -1640,6 +1643,9 @@ <h4 class="gslide-title"></h4>
let errorMessage;
if (error && error.response) {
switch (error.response.status) {
case 400:
errorMessage = "fs.rename.err_unsupported";
break;
case 403:
errorMessage = "fs.rename.err_403";
break;
Expand Down

0 comments on commit d92f85d

Please sign in to comment.