diff options
author | Alan Pearce | 2025-03-12 22:39:51 +0100 |
---|---|---|
committer | Alan Pearce | 2025-03-12 22:39:51 +0100 |
commit | 9015baf955c94a806c01b3dcd5648c8e68ad2685 (patch) | |
tree | 5f59386c2ab31b6e45b85576e45a1fc8ae448ae0 /internal/file/utils.go | |
parent | 7bb77ff5729cc9434afee895a470fd3b4c12e6d1 (diff) | |
download | searchix-9015baf955c94a806c01b3dcd5648c8e68ad2685.tar.lz searchix-9015baf955c94a806c01b3dcd5648c8e68ad2685.tar.zst searchix-9015baf955c94a806c01b3dcd5648c8e68ad2685.zip |
refactor: ensure errors have stack traces
Diffstat (limited to 'internal/file/utils.go')
-rw-r--r-- | internal/file/utils.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/internal/file/utils.go b/internal/file/utils.go index efcf0f6..eb04fa0 100644 --- a/internal/file/utils.go +++ b/internal/file/utils.go @@ -5,10 +5,10 @@ import ( "io/fs" "os" - "github.com/pkg/errors" + "gitlab.com/tozd/go/errors" ) -func Mkdirp(dir string) error { +func Mkdirp(dir string) errors.E { err := os.MkdirAll(dir, os.ModeDir|os.ModePerm) if err != nil { return errors.WithMessagef(err, "could not create directory %s", dir) @@ -17,27 +17,27 @@ func Mkdirp(dir string) error { return nil } -func NeedNotExist(err error) error { +func NeedNotExist(err error) errors.E { if err != nil && !errors.Is(err, fs.ErrNotExist) { - return err + return errors.WithStack(err) } return nil } -func StatIfExists(file string) (fs.FileInfo, error) { +func StatIfExists(file string) (fs.FileInfo, errors.E) { stat, err := os.Stat(file) return stat, NeedNotExist(err) } -func Exists(file string) (bool, error) { +func Exists(file string) (bool, errors.E) { stat, err := StatIfExists(file) return stat != nil, err } -func WriteToFile(path string, body io.Reader) error { +func WriteToFile(path string, body io.Reader) errors.E { file, err := os.Create(path) if err != nil { return errors.WithMessagef(err, "error creating file at %s", path) |