feat: switch from errors to fault
1 file changed, 13 insertions(+), 10 deletions(-)
changed files
M internal/fetcher/download.go → internal/fetcher/download.go
@@ -7,9 +7,10 @@ "alin.ovh/searchix/internal/config" "alin.ovh/searchix/internal/fetcher/http" "alin.ovh/searchix/internal/index" + "github.com/Southclaws/fault" + "github.com/Southclaws/fault/fmsg" "alin.ovh/x/log" - "gitlab.com/tozd/go/errors" ) type DownloadFetcher struct {@@ -21,7 +22,7 @@ func NewDownloadFetcher( source *config.Source, logger *log.Logger, -) (*DownloadFetcher, errors.E) { +) (*DownloadFetcher, error) { switch source.Importer { case config.Options, config.Packages: return &DownloadFetcher{@@ -29,7 +30,7 @@ Source: source, Logger: logger, }, nil default: - return nil, errors.Errorf("unsupported importer type %s", source.Importer) + return nil, fault.Newf("unsupported importer type %s", source.Importer) } }@@ -42,7 +43,7 @@ func (i *DownloadFetcher) FetchIfNeeded( ctx context.Context, sourceMeta *index.SourceMeta, -) (*FetchedFiles, errors.E) { +) (*FetchedFiles, error) { f := &FetchedFiles{} sourceUpdated := sourceMeta.Updated@@ -58,11 +59,13 @@ for _, filename := range filesToFetch { fetchURL, baseErr := url.JoinPath(i.Source.URL, filename) if baseErr != nil { - return nil, errors.WithMessagef( + return nil, fault.Wrap( baseErr, - "could not build URL with elements %s and %s", - i.Source.URL, - filename, + fmsg.Withf( + "could not build URL with elements %s and %s", + i.Source.URL, + filename, + ), ) }@@ -72,7 +75,7 @@ body, mtime, err := http.FetchFileIfNeeded(ctx, i.Logger, sourceUpdated, fetchURL) if err != nil { i.Logger.Warn("failed to fetch file", "url", fetchURL, "error", err) - return nil, err + return nil, fault.Wrap(err, fmsg.Withf("could not fetch file %s", filename)) } // don't bother to issue requests for the later files if mtime.Before(sourceUpdated) {@@ -88,7 +91,7 @@ f.Options = body case files["packages"]: f.Packages = body default: - return f, errors.Errorf("unknown filename %s", filename) + return f, fault.Newf("unknown filename %s", filename) } }