replace tozd/errors with Southclaws/fault
1 file changed, 15 insertions(+), 10 deletions(-)
changed files
M internal/storage/files/reader.go → internal/storage/files/reader.go
@@ -1,6 +1,7 @@ package files import ( + "fmt" "io/fs" "path/filepath" "strings"@@ -8,7 +9,8 @@ "go.alanpearce.eu/homestead/internal/storage" "go.alanpearce.eu/x/log" - "gitlab.com/tozd/go/errors" + "github.com/Southclaws/fault" + "github.com/Southclaws/fault/fmsg" ) type Reader struct {@@ -17,23 +19,23 @@ log *log.Logger files map[string]*storage.File } -func NewReader(path string, log *log.Logger) (*Reader, errors.E) { +func NewReader(path string, log *log.Logger) (*Reader, error) { r := &Reader{ root: path, log: log, files: make(map[string]*storage.File), } if err := r.registerContentFiles(); err != nil { - return nil, errors.WithMessagef(err, "registering content files") + return nil, fault.Wrap(err, fmsg.With("registering content files")) } return r, nil } -func (r *Reader) registerFile(urlpath string, filepath string) errors.E { +func (r *Reader) registerFile(urlpath string, filepath string) error { file, err := r.OpenFile(urlpath, filepath) if err != nil { - return errors.WithMessagef(err, "could not register file %s", filepath) + return fault.Wrap(err, fmsg.With(fmt.Sprintf("could not register file %s", filepath))) } r.files[urlpath] = file@@ -41,10 +43,10 @@ return nil } -func (r *Reader) registerContentFiles() errors.E { +func (r *Reader) registerContentFiles() error { err := filepath.WalkDir(r.root, func(filePath string, f fs.DirEntry, err error) error { if err != nil { - return errors.WithMessagef(err, "failed to access path %s", filePath) + return fault.Wrap(err, fmsg.With(fmt.Sprintf("failed to access path %s", filePath))) } if f.IsDir() { return nil@@ -52,7 +54,10 @@ } relPath, err := filepath.Rel(r.root, filePath) if err != nil { - return errors.WithMessagef(err, "failed to make path relative, path: %s", filePath) + return fault.Wrap( + err, + fmsg.With(fmt.Sprintf("failed to make path relative, path: %s", filePath)), + ) } urlPath := fileNameToPathName("/" + relPath)@@ -66,13 +71,13 @@ return r.registerFile(urlPath, filePath) }) if err != nil { - return errors.WithMessage(err, "could not walk directory") + return fault.Wrap(err, fmsg.With("could not walk directory")) } return nil } -func (r *Reader) GetFile(urlPath string) (*storage.File, errors.E) { +func (r *Reader) GetFile(urlPath string) (*storage.File, error) { return r.files[urlPath], nil }