From d77dea733f7d6d935873e6cfd2331a95f3feca5f Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Thu, 23 Jun 2022 16:03:27 +0800 Subject: [PATCH] chore: rename errors --- internal/aria2/add.go | 2 +- internal/errs/errors.go | 21 ++++++++++++--------- internal/fs/put.go | 2 +- internal/fs/write.go | 2 +- internal/operations/fs.go | 8 ++++---- internal/store/error.go | 7 ------- internal/store/meta.go | 3 ++- 7 files changed, 21 insertions(+), 24 deletions(-) delete mode 100644 internal/store/error.go diff --git a/internal/aria2/add.go b/internal/aria2/add.go index 72d23ef5..b082ec3d 100644 --- a/internal/aria2/add.go +++ b/internal/aria2/add.go @@ -20,7 +20,7 @@ func AddURI(ctx context.Context, uri string, dstDirPath string) error { } // check is it could upload if account.Config().NoUpload { - return errors.WithStack(errs.ErrUploadNotSupported) + return errors.WithStack(errs.UploadNotSupported) } // check path is valid obj, err := operations.Get(ctx, account, dstDirActualPath) diff --git a/internal/errs/errors.go b/internal/errs/errors.go index 5d95822c..80a202cb 100644 --- a/internal/errs/errors.go +++ b/internal/errs/errors.go @@ -6,16 +6,19 @@ import ( ) var ( - ErrorObjectNotFound = errors.New("object not found") - ErrNotImplement = errors.New("not implement") - ErrNotSupport = errors.New("not support") - ErrRelativePath = errors.New("access using relative path is not allowed") + ObjectNotFound = errors.New("object not found") + NotImplement = errors.New("not implement") + NotSupport = errors.New("not support") + RelativePath = errors.New("access using relative path is not allowed") - ErrMoveBetweenTwoAccounts = errors.New("can't move files between two account, try to copy") - ErrUploadNotSupported = errors.New("upload not supported") - ErrNotFolder = errors.New("not a folder") + MoveBetweenTwoAccounts = errors.New("can't move files between two account, try to copy") + UploadNotSupported = errors.New("upload not supported") + NotFolder = errors.New("not a folder") + NotFile = errors.New("not a file") + + MetaNotFound = errors.New("meta not found") ) -func IsErrObjectNotFound(err error) bool { - return pkgerr.Cause(err) == ErrorObjectNotFound +func IsObjectNotFound(err error) bool { + return pkgerr.Cause(err) == ObjectNotFound } diff --git a/internal/fs/put.go b/internal/fs/put.go index 0416f6ba..86318e7e 100644 --- a/internal/fs/put.go +++ b/internal/fs/put.go @@ -20,7 +20,7 @@ var UploadTaskManager = task.NewTaskManager[uint64](3, func(tid *uint64) { func Put(ctx context.Context, account driver.Driver, dstDirPath string, file model.FileStreamer) error { account, dstDirActualPath, err := operations.GetAccountAndActualPath(dstDirPath) if account.Config().NoUpload { - return errors.WithStack(errs.ErrUploadNotSupported) + return errors.WithStack(errs.UploadNotSupported) } if err != nil { return errors.WithMessage(err, "failed get account") diff --git a/internal/fs/write.go b/internal/fs/write.go index 32ce2696..eb634a6c 100644 --- a/internal/fs/write.go +++ b/internal/fs/write.go @@ -26,7 +26,7 @@ func Move(ctx context.Context, account driver.Driver, srcPath, dstDirPath string return errors.WithMessage(err, "failed get dst account") } if srcAccount.GetAccount() != dstAccount.GetAccount() { - return errors.WithStack(errs.ErrMoveBetweenTwoAccounts) + return errors.WithStack(errs.MoveBetweenTwoAccounts) } return operations.Move(ctx, account, srcActualPath, dstDirActualPath) } diff --git a/internal/operations/fs.go b/internal/operations/fs.go index 8271eac1..c78a9702 100644 --- a/internal/operations/fs.go +++ b/internal/operations/fs.go @@ -86,7 +86,7 @@ func Get(ctx context.Context, account driver.Driver, path string) (model.Obj, er return f, nil } } - return nil, errors.WithStack(errs.ErrorObjectNotFound) + return nil, errors.WithStack(errs.ObjectNotFound) } var linkCache = cache.NewMemCache(cache.WithShards[*model.Link](16)) @@ -104,7 +104,7 @@ func Link(ctx context.Context, account driver.Driver, path string, args model.Li return nil, errors.WithMessage(err, "failed to get file") } if file.IsDir() { - return nil, errors.New("file is dir") + return nil, errors.WithStack(errs.NotFile) } link, err := account.Link(ctx, file, args) if err != nil { @@ -123,7 +123,7 @@ func MakeDir(ctx context.Context, account driver.Driver, path string) error { // check if dir exists f, err := Get(ctx, account, path) if err != nil { - if errs.IsErrObjectNotFound(err) { + if errs.IsObjectNotFound(err) { parentPath, dirName := stdpath.Split(path) err = MakeDir(ctx, account, parentPath) if err != nil { @@ -183,7 +183,7 @@ func Remove(ctx context.Context, account driver.Driver, path string) error { obj, err := Get(ctx, account, path) if err != nil { // if object not found, it's ok - if errs.IsErrObjectNotFound(err) { + if errs.IsObjectNotFound(err) { return nil } return errors.WithMessage(err, "failed to get object") diff --git a/internal/store/error.go b/internal/store/error.go deleted file mode 100644 index 24bff4d5..00000000 --- a/internal/store/error.go +++ /dev/null @@ -1,7 +0,0 @@ -package store - -import "errors" - -var ( - ErrMetaNotFound = errors.New("meta not found") -) diff --git a/internal/store/meta.go b/internal/store/meta.go index 2922d15b..e44b6bc0 100644 --- a/internal/store/meta.go +++ b/internal/store/meta.go @@ -2,6 +2,7 @@ package store import ( "github.com/Xhofe/go-cache" + "github.com/alist-org/alist/v3/internal/errs" "github.com/alist-org/alist/v3/internal/model" "github.com/alist-org/alist/v3/pkg/singleflight" "github.com/alist-org/alist/v3/pkg/utils" @@ -25,7 +26,7 @@ func GetNearestMeta(path string) (*model.Meta, error) { return nil, err } if path == "/" { - return nil, errors.WithStack(ErrMetaNotFound) + return nil, errors.WithStack(errs.MetaNotFound) } return GetNearestMeta(stdpath.Dir(path)) }