feat: switch from errors to fault
1 file changed, 12 insertions(+), 10 deletions(-)
changed files
M internal/file/utils.go → internal/file/utils.go
@@ -1,52 +1,54 @@ package file import ( + "errors" "io" "io/fs" "os" - "gitlab.com/tozd/go/errors" + "github.com/Southclaws/fault" + "github.com/Southclaws/fault/fmsg" ) -func Mkdirp(dir string) errors.E { +func Mkdirp(dir string) error { err := os.MkdirAll(dir, os.ModeDir|os.ModePerm) if err != nil { - return errors.WithMessagef(err, "could not create directory %s", dir) + return fault.Wrap(err, fmsg.Withf("could not create directory %s", dir)) } return nil } -func NeedNotExist(err error) errors.E { +func NeedNotExist(err error) error { if err != nil && !errors.Is(err, fs.ErrNotExist) { - return errors.WithStack(err) + return fault.Wrap(err) } return nil } -func StatIfExists(file string) (fs.FileInfo, errors.E) { +func StatIfExists(file string) (fs.FileInfo, error) { stat, err := os.Stat(file) return stat, NeedNotExist(err) } -func Exists(file string) (bool, errors.E) { +func Exists(file string) (bool, error) { stat, err := StatIfExists(file) return stat != nil, err } -func WriteToFile(path string, body io.Reader) errors.E { +func WriteToFile(path string, body io.Reader) error { file, err := os.Create(path) if err != nil { - return errors.WithMessagef(err, "error creating file at %s", path) + return fault.Wrap(err, fmsg.Withf("error creating file at %s", path)) } defer file.Close() _, err = io.Copy(file, body) if err != nil { - return errors.WithMessagef(err, "error downloading file %s", path) + return fault.Wrap(err, fmsg.Withf("error downloading file %s", path)) } return nil