replace tozd/errors with Southclaws/fault
1 file changed, 16 insertions(+), 15 deletions(-)
changed files
M internal/builder/template/template.go → internal/builder/template/template.go
@@ -12,9 +12,10 @@ "go.alanpearce.eu/homestead/internal/content" "go.alanpearce.eu/homestead/templates" "github.com/PuerkitoBio/goquery" + "github.com/Southclaws/fault" + "github.com/Southclaws/fault/fmsg" "github.com/antchfx/xmlquery" "github.com/antchfx/xpath" - "gitlab.com/tozd/go/errors" ) var (@@ -25,16 +26,16 @@ "xhtml": "http://www.w3.org/1999/xhtml", } ) -func RenderRobotsTXT(baseURL config.URL, w io.Writer) errors.E { +func RenderRobotsTXT(baseURL config.URL, w io.Writer) error { tpl, err := template.ParseFS(templates.Files, "robots.tmpl") if err != nil { - return errors.WithStack(err) + return fault.Wrap(err) } err = tpl.Execute(w, map[string]any{ "BaseURL": baseURL, }) if err != nil { - return errors.WithStack(err) + return fault.Wrap(err) } return nil@@ -45,7 +46,7 @@ title string, config *config.Config, posts []*content.Post, specific string, -) (io.WriterTo, errors.E) { +) (io.WriterTo, error) { buf := &bytes.Buffer{} datetime := posts[0].Date.UTC()@@ -65,7 +66,7 @@ for i, post := range posts { html, err := post.RenderString() if err != nil { - return nil, errors.WithMessage(err, "could not render post") + return nil, fault.Wrap(err, fmsg.With("could not render post")) } feed.Entries[i] = &atom.FeedEntry{ Title: post.Title,@@ -82,44 +83,44 @@ } } enc := xml.NewEncoder(buf) if err := enc.Encode(feed); err != nil { - return nil, errors.WithStack(err) + return nil, fault.Wrap(err) } return buf, nil } -func CopyFile(filename string, w io.Writer) errors.E { +func CopyFile(filename string, w io.Writer) error { f, err := templates.Files.Open(filename) if err != nil { - return errors.WithStack(err) + return fault.Wrap(err) } defer f.Close() if _, err := io.Copy(w, f); err != nil { - return errors.WithStack(err) + return fault.Wrap(err) } return nil } -func GetFeedStyleHash(r io.Reader) (string, errors.E) { +func GetFeedStyleHash(r io.Reader) (string, error) { doc, err := xmlquery.Parse(r) if err != nil { - return "", errors.WithStack(err) + return "", fault.Wrap(err) } expr, err := xpath.CompileWithNS("//xhtml:style", nsMap) if err != nil { - return "", errors.WithMessage(err, "could not parse XPath") + return "", fault.Wrap(err, fmsg.With("could not parse XPath")) } style := xmlquery.QuerySelector(doc, expr) return Hash(style.InnerText()), nil } -func GetHTMLStyleHash(r io.Reader) (string, errors.E) { +func GetHTMLStyleHash(r io.Reader) (string, error) { doc, err := goquery.NewDocumentFromReader(r) if err != nil { - return "", errors.WithStack(err) + return "", fault.Wrap(err) } html := doc.Find("head > style").Text()