diff --git a/internal/laboratory/test-traverse-fs.go b/internal/laboratory/test-traverse-fs.go index 6dd73a6..1abb113 100644 --- a/internal/laboratory/test-traverse-fs.go +++ b/internal/laboratory/test-traverse-fs.go @@ -8,7 +8,6 @@ import ( nef "github.com/snivilised/nefilim" "github.com/snivilised/traverse/internal/third/lo" - "github.com/snivilised/traverse/locale" ) type testMapFile struct { @@ -55,7 +54,7 @@ func (f *TestTraverseFS) Create(name string) (*os.File, error) { func (f *TestTraverseFS) MakeDir(name string, perm os.FileMode) error { if !fs.ValidPath(name) { - return locale.NewInvalidPathError(name) + return nef.NewInvalidPathError("MakeDir", name) } if _, found := f.MapFS[name]; !found { @@ -69,7 +68,7 @@ func (f *TestTraverseFS) MakeDir(name string, perm os.FileMode) error { func (f *TestTraverseFS) MakeDirAll(name string, perm os.FileMode) error { if !fs.ValidPath(name) { - return locale.NewInvalidPathError(name) + return nef.NewInvalidPathError("MakeDir", name) } segments := strings.Split(name, "/") diff --git a/locale/messages-errors.go b/locale/messages-errors.go index ef8293d..d1e7def 100644 --- a/locale/messages-errors.go +++ b/locale/messages-errors.go @@ -595,194 +595,3 @@ func (td InvalidPathTemplData) Message() *i18n.Message { Other: "path: {{.Path}}", } } - -type InvalidPathError struct { - li18ngo.LocalisableError - Wrapped error -} - -func (e InvalidPathError) Error() string { - wrapped := e.Wrapped.Error() - path := li18ngo.Text(e.Data) - return fmt.Sprintf("%v, %v", wrapped, path) -} - -func (e InvalidPathError) Unwrap() error { - return e.Wrapped -} - -func NewInvalidPathError(path string) error { - return &InvalidPathError{ - LocalisableError: li18ngo.LocalisableError{ - Data: InvalidPathTemplData{ - Path: path, - }, - }, - Wrapped: errCoreInvalidPath, - } -} - -// ❌ CoreInvalidPathError - -type CoreInvalidPathErrorTemplData struct { - traverseTemplData -} - -func IsInvalidPathError(err error) bool { - return errors.Is(err, errCoreInvalidPath) -} - -func (td CoreInvalidPathErrorTemplData) Message() *i18n.Message { - return &i18n.Message{ - ID: "invalid-path.core-error", - Description: "invalid path core error", - Other: "invalid path", - } -} - -type CoreInvalidPathError struct { - li18ngo.LocalisableError -} - -var errCoreInvalidPath = CoreInvalidPathError{ - LocalisableError: li18ngo.LocalisableError{ - Data: CoreInvalidPathErrorTemplData{}, - }, -} - -// BOOKMARK - -// ❌ InvalidBinaryFsOp, can be used to adapt the non i18n nefilim.InvalidBinaryFsOp -// error into an i18n one. - -type InvalidBinaryFsOpTemplData struct { - traverseTemplData - From string - To string - Op string -} - -func (td InvalidBinaryFsOpTemplData) Message() *i18n.Message { - return &i18n.Message{ - ID: "invalid-binary-op.dynamic-error", - Description: "invalid binary op dynamic error", - Other: "tbd: {{.Field}}", - } -} - -type InvalidBinaryFsOpError struct { - li18ngo.LocalisableError - Wrapped error -} - -func (e InvalidBinaryFsOpError) Error() string { - return fmt.Sprintf("%v, %v", e.Wrapped.Error(), li18ngo.Text(e.Data)) -} - -func (e InvalidBinaryFsOpError) Unwrap() error { - return e.Wrapped -} - -func NewInvalidBinaryFsOpError(op, from, to string) error { - return &InvalidBinaryFsOpError{ - LocalisableError: li18ngo.LocalisableError{ - Data: InvalidBinaryFsOpTemplData{ - From: from, - To: to, - Op: op, - }, - }, - Wrapped: errCoreInvalidBinaryFsOp, // replace with nefilim version - } -} - -// ❌ CoreInvalidBinaryFsOp - -type CoreInvalidBinaryFsOpErrorTemplData struct { - traverseTemplData -} - -func IsInvalidBinaryFsOpError(err error) bool { - return errors.Is(err, errCoreInvalidBinaryFsOp) -} - -func (td CoreInvalidBinaryFsOpErrorTemplData) Message() *i18n.Message { - return &i18n.Message{ - ID: "invalid-binary-op.core-error", - Description: "invalid binary op core error", - Other: "invalid binary op", - } -} - -// will be replaced by nefilim.CoreInvalidBinaryFsOpError -type CoreInvalidBinaryFsOpError struct { - li18ngo.LocalisableError -} - -// this will be replaced by the nefilim.errCoreInvalidBinaryFsOp error -var errCoreInvalidBinaryFsOp = CoreInvalidBinaryFsOpError{ - LocalisableError: li18ngo.LocalisableError{ - Data: CoreInvalidBinaryFsOpErrorTemplData{}, - }, -} - -// ❌ RejectSameDirMoveError; replace with nefilim version - -// RejectSameDirMoveErrorTemplDataL invalid file system operation -// that involves 2 paths, typically a source and destination. -// The error also indicates which operation is at fault. -type RejectSameDirMoveErrorTemplDataL struct { - traverseTemplData - From string - To string - Op string -} - -// IsInvalidExtGlobFilterMissingSeparatorError uses errors.Is to check -// if the err's error tree contains the core error: -// InvalidExtGlobFilterMissingSeparatorError -func IsRejectSameDirMoveErrorL(err error) bool { - return errors.Is(err, errCoreRejectSameDirMoveErrorL) -} - -func NewRejectSameDirMoveErrorL(op, from, to string) error { - return errors.Wrap( - errCoreRejectSameDirMoveErrorL, - li18ngo.Text(RejectSameDirMoveErrorTemplDataL{ - From: from, - To: to, - Op: op, - }), - ) -} - -// Message -func (td RejectSameDirMoveErrorTemplDataL) Message() *i18n.Message { - return &i18n.Message{ - ID: "reject-same-dir-move.error", - Description: "Reject same directory move operation as this is just a rename", - Other: "{{.Op}}, from: {{.From}}, to {{.To}}", - } -} - -// ❌ CoreRejectSameDirMoveError; replace with nefilim version - -type CoreRejectSameDirMoveErrorTemplDataL struct { - traverseTemplData - li18ngo.LocalisableError -} - -func (td CoreRejectSameDirMoveErrorTemplDataL) Message() *i18n.Message { - return &i18n.Message{ - ID: "core-reject-same-dir-move.error", - Description: "Core reject same directory move operation as this is just a rename", - Other: "same directory move rejected; use rename instead", - } -} - -// replace with nefilim version -var errCoreRejectSameDirMoveErrorL = CoreRejectSameDirMoveErrorTemplDataL{ - LocalisableError: li18ngo.LocalisableError{ - Data: CoreRejectSameDirMoveErrorTemplDataL{}, - }, -}