Skip to content

Commit

Permalink
ref(nef): export errors (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Oct 19, 2024
1 parent 3b635b7 commit f96c2d6
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,38 @@ import (

// IsInvalidPathError
func IsInvalidPathError(err error) bool {
return errors.Is(err, errCoreInvalidPath)
return errors.Is(err, ErrCoreInvalidPath)
}

// NewInvalidPathError
func NewInvalidPathError(path string) error {
return fmt.Errorf("path: %q, %w", path, errCoreInvalidPath)
return fmt.Errorf("path: %q, %w", path, ErrCoreInvalidPath)
}

// IsBinaryFsOpError
func IsBinaryFsOpError(err error) bool {
return errors.Is(err, errCoreBinaryFsOp)
return errors.Is(err, ErrCoreBinaryFsOp)
}

// NewInvalidBinaryFsOpError
func NewInvalidBinaryFsOpError(op, from, to string) error {
return fmt.Errorf("op: %q, from %q, to: %q %w", op, from, to, errCoreBinaryFsOp)
return fmt.Errorf("op: %q, from %q, to: %q %w", op, from, to, ErrCoreBinaryFsOp)
}

// IsRejectSameDirMoveError
func IsRejectSameDirMoveError(err error) bool {
return errors.Is(err, errCoreRejectSameDirMove)
return errors.Is(err, ErrCoreRejectSameDirMove)
}

// NewRejectSameDirMoveError
func NewRejectSameDirMoveError(op, from, to string) error {
return fmt.Errorf("op: %q, from %q, to: %q %w", op, from, to, errCoreRejectSameDirMove)
return fmt.Errorf("op: %q, from %q, to: %q %w", op, from, to, ErrCoreRejectSameDirMove)
}

// these errors are deliberately being exported, so that client libraries (eg traverse) that do support i18n
// can wrap them and make them translate-able.
var (
errCoreInvalidPath = errors.New("invalid path")
errCoreBinaryFsOp = errors.New("invalid binary file system operation")
errCoreRejectSameDirMove = errors.New("same directory move rejected, use move instead")
ErrCoreInvalidPath = errors.New("invalid path")
ErrCoreBinaryFsOp = errors.New("invalid binary file system operation")
ErrCoreRejectSameDirMove = errors.New("same directory move rejected, use move instead")
)

0 comments on commit f96c2d6

Please sign in to comment.