all repos — homestead @ 4c07535d9120fb999b0c008f1866972865f424f7

Code for my website

replace tozd/errors with Southclaws/fault

Alan Pearce
commit

4c07535d9120fb999b0c008f1866972865f424f7

parent

90a4ac43b915abb7a2949f4b5313b40d705b6071

1 file changed, 18 insertions(+), 10 deletions(-)

changed files
M internal/events/file.gointernal/events/file.go
@@ -1,6 +1,7 @@
package events import ( + "fmt" "io/fs" "maps" "os"
@@ -11,8 +12,9 @@ "time"
"go.alanpearce.eu/x/log" + "github.com/Southclaws/fault" + "github.com/Southclaws/fault/fmsg" "github.com/fsnotify/fsnotify" - "gitlab.com/tozd/go/errors" ) var (
@@ -28,10 +30,10 @@ log *log.Logger
*fsnotify.Watcher } -func NewFileWatcher(logger *log.Logger, dirs ...string) (*FileWatcher, errors.E) { +func NewFileWatcher(logger *log.Logger, dirs ...string) (*FileWatcher, error) { fsn, err := fsnotify.NewWatcher() if err != nil { - return nil, errors.WithMessage(err, "could not create file watcher") + return nil, fault.Wrap(err, fmsg.With("could not create file watcher")) } fw := &FileWatcher{
@@ -42,7 +44,10 @@
for _, dir := range dirs { err = fw.AddRecursive(dir) if err != nil { - return nil, errors.WithMessagef(err, "could not add directory %s to file watcher", dir) + return nil, fault.Wrap( + err, + fmsg.With(fmt.Sprintf("could not add directory %s to file watcher", dir)), + ) } }
@@ -64,11 +69,11 @@ func (fw *FileWatcher) ignored(pathname string) bool {
return slices.ContainsFunc(ignores, fw.matches(path.Base(pathname))) } -func (fw *FileWatcher) AddRecursive(from string) errors.E { +func (fw *FileWatcher) AddRecursive(from string) error { fw.log.Debug("walking directory tree", "root", from) err := filepath.WalkDir(from, func(path string, entry fs.DirEntry, err error) error { if err != nil { - return errors.WithMessagef(err, "could not walk directory %s", path) + return fault.Wrap(err, fmsg.With(fmt.Sprintf("could not walk directory %s", path))) } if entry.IsDir() { if entry.Name() == ".git" {
@@ -78,21 +83,24 @@ return fs.SkipDir
} fw.log.Debug("adding directory to watcher", "path", path) if err = fw.Add(path); err != nil { - return errors.WithMessagef(err, "could not add directory %s to watcher", path) + return fault.Wrap( + err, + fmsg.With(fmt.Sprintf("could not add directory %s to watcher", path)), + ) } } return nil }) - return errors.WithMessage(err, "error walking directory tree") + return fault.Wrap(err, fmsg.With("error walking directory tree")) } -func (fw *FileWatcher) GetLatestRunID() (uint64, errors.E) { +func (fw *FileWatcher) GetLatestRunID() (uint64, error) { return 0, nil } -func (fw *FileWatcher) Subscribe() (<-chan Event, errors.E) { +func (fw *FileWatcher) Subscribe() (<-chan Event, error) { var timer *time.Timer events := make(chan Event, 1)