all repos — searchix @ 3dfbd8dd7212f74622ba4892efb34bf3487da09b

Search engine for NixOS, nix-darwin, home-manager and NUR users

feat: switch from errors to fault

Alan Pearce
commit

3dfbd8dd7212f74622ba4892efb34bf3487da09b

parent

e72b060271452e25bbcb2799fc19996ff73689fd

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

changed files
M internal/fetcher/http/http.gointernal/fetcher/http/http.go
@@ -11,8 +11,9 @@
"alin.ovh/searchix/internal/config" "alin.ovh/x/log" + "github.com/Southclaws/fault" + "github.com/Southclaws/fault/fmsg" "github.com/andybalholm/brotli" - "gitlab.com/tozd/go/errors" ) type brotliReadCloser struct {
@@ -28,7 +29,7 @@ }
} func (r *brotliReadCloser) Close() error { - return errors.Wrap(r.src.Close(), "failed to call close on underlying reader") + return fault.Wrap(r.src.Close(), fmsg.With("failed to call close on underlying reader")) } func FetchFileIfNeeded(
@@ -36,7 +37,7 @@ ctx context.Context,
log *log.Logger, mtime time.Time, url string, -) (io.ReadCloser, time.Time, errors.E) { +) (io.ReadCloser, time.Time, error) { var newMtime time.Time var ifModifiedSince string if !mtime.IsZero() {
@@ -45,10 +46,9 @@ }
req, baseErr := http.NewRequestWithContext(ctx, "GET", url, http.NoBody) if baseErr != nil { - return nil, newMtime, errors.WithMessagef( + return nil, newMtime, fault.Wrap( baseErr, - "could not create HTTP request for %s", - url, + fmsg.Withf("could not create HTTP request for %s", url), ) }
@@ -59,11 +59,14 @@ req.Header.Set("If-Modified-Since", ifModifiedSince)
} res, baseErr := http.DefaultClient.Do(req) if baseErr != nil { - return nil, newMtime, errors.WithMessagef(baseErr, "could not make HTTP request to %s", url) + return nil, newMtime, fault.Wrap( + baseErr, + fmsg.Withf("could not make HTTP request to %s", url), + ) } var body io.ReadCloser - var err errors.E + var err error switch res.StatusCode { case http.StatusNotModified: newMtime = mtime
@@ -88,10 +91,10 @@ body = newBrotliReader(res.Body)
case "", "identity", "gzip": body = res.Body default: - err = errors.Errorf("cannot handle a body with content-encoding %s", ce) + err = fault.Newf("cannot handle a body with content-encoding %s", ce) } default: - err = errors.Errorf("got response code %d, don't know what to do", res.StatusCode) + err = fault.Newf("got response code %d, don't know what to do", res.StatusCode) } return NewReadCloser(body), newMtime, err