Skip to content

Commit

Permalink
ref(locale): clean up old i18n errors (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Oct 24, 2024
1 parent 5d1eb98 commit b6bfd16
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 194 deletions.
5 changes: 2 additions & 3 deletions internal/laboratory/test-traverse-fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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, "/")
Expand Down
191 changes: 0 additions & 191 deletions locale/messages-errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
},
}

0 comments on commit b6bfd16

Please sign in to comment.