replace tozd/errors with Southclaws/fault
1 file changed, 14 insertions(+), 12 deletions(-)
changed files
M internal/file/file.go → internal/file/file.go
@@ -1,18 +1,20 @@ package file import ( + "errors" "io" "io/fs" "os" "path/filepath" - "gitlab.com/tozd/go/errors" + "github.com/Southclaws/fault" + "github.com/Southclaws/fault/fmsg" ) -func Stat(path string) (fs.FileInfo, errors.E) { +func Stat(path string) (fs.FileInfo, error) { stat, err := os.Stat(path) if err != nil && !errors.Is(err, fs.ErrNotExist) { - return nil, errors.WithStack(err) + return nil, fault.Wrap(err) } return stat, nil@@ -27,45 +29,45 @@ return stat != nil } -func Copy(src, dest string) errors.E { +func Copy(src, dest string) error { stat, err := os.Stat(src) if err != nil { - return errors.WithMessage(err, "could not stat source file") + return fault.Wrap(err, fmsg.With("could not stat source file")) } sf, err := os.Open(src) if err != nil { - return errors.WithMessage(err, "could not open source file for reading") + return fault.Wrap(err, fmsg.With("could not open source file for reading")) } defer sf.Close() df, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE, stat.Mode()) if err != nil { - return errors.WithMessage(err, "could not open destination file for writing") + return fault.Wrap(err, fmsg.With("could not open destination file for writing")) } defer df.Close() if _, err := io.Copy(df, sf); err != nil { - return errors.WithMessage(err, "could not copy") + return fault.Wrap(err, fmsg.With("could not copy")) } err = df.Sync() if err != nil { - return errors.WithMessage(err, "could not call fsync") + return fault.Wrap(err, fmsg.With("could not call fsync")) } return nil } -func CleanDir(dir string) errors.E { +func CleanDir(dir string) error { files, err := os.ReadDir(dir) if err != nil { - return errors.WithMessage(errors.WithStack(err), "could not read directory") + return fault.Wrap(fault.Wrap(err), fmsg.With("could not read directory")) } for _, file := range files { err = errors.Join(err, os.RemoveAll(filepath.Join(dir, file.Name()))) } - return errors.WithStack(err) + return fault.Wrap(err) }