Skip to content

Commit

Permalink
chore: rename errors
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jun 23, 2022
1 parent fd5c3e8 commit d77dea7
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion internal/aria2/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 12 additions & 9 deletions internal/errs/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion internal/fs/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion internal/fs/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/operations/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
7 changes: 0 additions & 7 deletions internal/store/error.go

This file was deleted.

3 changes: 2 additions & 1 deletion internal/store/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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))
}
Expand Down

0 comments on commit d77dea7

Please sign in to comment.