about summary refs log tree commit diff stats
path: root/internal
diff options
context:
space:
mode:
authorAlan Pearce2024-11-28 15:12:00 +0100
committerAlan Pearce2024-11-28 15:12:00 +0100
commitb94f66cfe5bf87ec6d2a32448ca5c55ba118c7aa (patch)
treeeb6f951b3a0959c6ace7be6f111124791e90c54d /internal
parent183b0c8b5edbcf4224d4dd3905ca483204522656 (diff)
downloadwebsite-b94f66cfe5bf87ec6d2a32448ca5c55ba118c7aa.tar.lz
website-b94f66cfe5bf87ec6d2a32448ca5c55ba118c7aa.tar.zst
website-b94f66cfe5bf87ec6d2a32448ca5c55ba118c7aa.zip
Use errors.WithMessage in place of .Wrap
Diffstat (limited to 'internal')
-rw-r--r--internal/builder/builder.go4
-rw-r--r--internal/builder/template.go4
-rw-r--r--internal/config/config.go4
-rw-r--r--internal/config/cspgenerator.go18
-rw-r--r--internal/server/server.go4
-rw-r--r--internal/server/tls.go12
-rw-r--r--internal/website/filemap.go6
7 files changed, 26 insertions, 26 deletions
diff --git a/internal/builder/builder.go b/internal/builder/builder.go
index b99d919..bb39c43 100644
--- a/internal/builder/builder.go
+++ b/internal/builder/builder.go
@@ -12,9 +12,9 @@ import (
 
 	"go.alanpearce.eu/website/internal/config"
 	"go.alanpearce.eu/website/internal/content"
-	"go.alanpearce.eu/x/log"
 	"go.alanpearce.eu/website/internal/sitemap"
 	"go.alanpearce.eu/website/templates"
+	"go.alanpearce.eu/x/log"
 
 	"github.com/a-h/templ"
 	mapset "github.com/deckarep/golang-set/v2"
@@ -36,7 +36,7 @@ var compressFiles = false
 func mkdirp(dirs ...string) error {
 	err := os.MkdirAll(path.Join(dirs...), 0755)
 
-	return errors.Wrap(err, "could not create directory")
+	return errors.WithMessage(err, "could not create directory")
 }
 
 func outputToFile(output io.Reader, pathParts ...string) error {
diff --git a/internal/builder/template.go b/internal/builder/template.go
index 9f019df..c318107 100644
--- a/internal/builder/template.go
+++ b/internal/builder/template.go
@@ -47,7 +47,7 @@ type QueryDocument struct {
 func NewDocumentFromReader(r io.Reader) (*QueryDocument, error) {
 	doc, err := goquery.NewDocumentFromReader(r)
 
-	return &QueryDocument{doc}, errors.Wrap(err, "could not create query document")
+	return &QueryDocument{doc}, errors.WithMessage(err, "could not create query document")
 }
 
 func (q *QueryDocument) Find(selector string) *QuerySelection {
@@ -148,7 +148,7 @@ func getFeedStylesHash(r io.Reader) (string, error) {
 	}
 	expr, err := xpath.CompileWithNS("//xhtml:style", nsMap)
 	if err != nil {
-		return "", errors.Wrap(err, "could not parse XPath")
+		return "", errors.WithMessage(err, "could not parse XPath")
 	}
 	style := xmlquery.QuerySelector(doc, expr)
 
diff --git a/internal/config/config.go b/internal/config/config.go
index 7ccad85..000dc6f 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -28,7 +28,7 @@ type URL struct {
 func (u *URL) UnmarshalText(text []byte) (err error) {
 	u.URL, err = url.Parse(string(text))
 
-	return errors.Wrapf(err, "could not parse URL %s", string(text))
+	return errors.WithMessagef(err, "could not parse URL %s", string(text))
 }
 
 type Config struct {
@@ -65,7 +65,7 @@ func GetConfig(dir string, log *log.Logger) (*Config, error) {
 			return nil, errors.WithMessage(t, t.ErrorWithUsage())
 		}
 
-		return nil, errors.Wrap(err, "config error")
+		return nil, errors.WithMessage(err, "config error")
 	}
 
 	return &config, nil
diff --git a/internal/config/cspgenerator.go b/internal/config/cspgenerator.go
index 9974819..389e778 100644
--- a/internal/config/cspgenerator.go
+++ b/internal/config/cspgenerator.go
@@ -17,7 +17,7 @@ func GenerateCSP() error {
 	file, err := os.OpenFile("./csp.go", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0)
 	if err != nil {
 
-		return errors.Wrap(err, "could not write to output")
+		return errors.WithMessage(err, "could not write to output")
 	}
 	defer file.Close()
 
@@ -32,12 +32,12 @@ import (
 `)
 	if err != nil {
 
-		return errors.Wrap(err, "could not write to output")
+		return errors.WithMessage(err, "could not write to output")
 	}
 
 	_, err = fmt.Fprintf(file, "type CSP struct {\n")
 	if err != nil {
-		return errors.Wrap(err, "could not write to output")
+		return errors.WithMessage(err, "could not write to output")
 	}
 
 	for i := 0; i < t.NumField(); i++ {
@@ -46,28 +46,28 @@ import (
 		t = field.Type
 		tags, err := structtag.Parse(string(field.Tag))
 		if err != nil {
-			return errors.Wrap(err, "could not write to output")
+			return errors.WithMessage(err, "could not write to output")
 		}
 		cspTag, err := tags.Get("csp")
 		if err != nil {
-			return errors.Wrap(err, "could not get csp tag")
+			return errors.WithMessage(err, "could not get csp tag")
 		}
 		err = tags.Set(&structtag.Tag{
 			Key:  "toml",
 			Name: cspTag.Name,
 		})
 		if err != nil {
-			return errors.Wrap(err, "could not set toml tag")
+			return errors.WithMessage(err, "could not set toml tag")
 		}
 
 		_, err = fmt.Fprintf(file, "\t%-23s %-28s `%s`\n", field.Name, t, tags.String())
 		if err != nil {
-			return errors.Wrap(err, "could not write to output")
+			return errors.WithMessage(err, "could not write to output")
 		}
 	}
 	_, err = fmt.Fprintln(file, "}")
 	if err != nil {
-		return errors.Wrap(err, "could not write to output")
+		return errors.WithMessage(err, "could not write to output")
 	}
 
 	_, err = fmt.Fprintln(file, `
@@ -75,7 +75,7 @@ func (c *CSP) String() string {
 	return csp.Header(*c).String()
 }`)
 	if err != nil {
-		return errors.Wrap(err, "could not write to output")
+		return errors.WithMessage(err, "could not write to output")
 	}
 
 	return nil
diff --git a/internal/server/server.go b/internal/server/server.go
index 5c92139..b327f3d 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -180,7 +180,7 @@ func New(runtimeConfig *Config, log *log.Logger) (*Server, error) {
 	loggingMux := http.NewServeMux()
 	mux, err := website.NewMux(config, runtimeConfig.Root, log.Named("website"))
 	if err != nil {
-		return nil, errors.Wrap(err, "could not create website mux")
+		return nil, errors.WithMessage(err, "could not create website mux")
 	}
 
 	if runtimeConfig.Redirect {
@@ -238,7 +238,7 @@ func (s *Server) serve(tls bool) error {
 
 func (s *Server) Start() error {
 	if err := s.serve(s.runtimeConfig.TLS); err != http.ErrServerClosed {
-		return errors.Wrap(err, "error creating/closing server")
+		return errors.WithMessage(err, "error creating/closing server")
 	}
 
 	return nil
diff --git a/internal/server/tls.go b/internal/server/tls.go
index 2bb5ce4..716495c 100644
--- a/internal/server/tls.go
+++ b/internal/server/tls.go
@@ -73,13 +73,13 @@ func (s *Server) serveTLS() (err error) {
 		rc := &redisConfig{}
 		_, err = conf.Parse("REDIS", rc)
 		if err != nil {
-			return errors.Wrap(err, "could not parse redis config")
+			return errors.WithMessage(err, "could not parse redis config")
 		}
 
 		pdns := &powerdns.Provider{}
 		_, err = conf.Parse("POWERDNS", pdns)
 		if err != nil {
-			return errors.Wrap(err, "could not parse PowerDNS ACME config")
+			return errors.WithMessage(err, "could not parse PowerDNS ACME config")
 		}
 
 		issuer = certmagic.NewACMEIssuer(cfg, certmagic.ACMEIssuer{
@@ -113,7 +113,7 @@ func (s *Server) serveTLS() (err error) {
 			Context: context.Background(),
 		})
 		if err != nil {
-			return errors.Wrap(err, "could not provision redis storage")
+			return errors.WithMessage(err, "could not provision redis storage")
 		}
 	}
 	cfg.Issuers[0] = issuer
@@ -124,7 +124,7 @@ func (s *Server) serveTLS() (err error) {
 		log.Named("listenfd"),
 	)
 	if err != nil {
-		return errors.Wrap(err, "could not bind plain socket")
+		return errors.WithMessage(err, "could not bind plain socket")
 	}
 
 	go func(ln net.Listener, srv *http.Server) {
@@ -169,7 +169,7 @@ func (s *Server) serveTLS() (err error) {
 	)
 	err = cfg.ManageAsync(context.TODO(), certificateDomains)
 	if err != nil {
-		return errors.Wrap(err, "could not enable TLS")
+		return errors.WithMessage(err, "could not enable TLS")
 	}
 	tlsConfig := cfg.TLSConfig()
 	tlsConfig.NextProtos = append([]string{"h2", "http/1.1"}, tlsConfig.NextProtos...)
@@ -181,7 +181,7 @@ func (s *Server) serveTLS() (err error) {
 		log.Named("listenfd"),
 	)
 	if err != nil {
-		return errors.Wrap(err, "could not bind tls socket")
+		return errors.WithMessage(err, "could not bind tls socket")
 	}
 
 	return s.Serve(sln)
diff --git a/internal/website/filemap.go b/internal/website/filemap.go
index 64b914f..edef7cd 100644
--- a/internal/website/filemap.go
+++ b/internal/website/filemap.go
@@ -35,12 +35,12 @@ var files = map[string]*File{}
 func hashFile(filename string) (string, error) {
 	f, err := os.Open(filename)
 	if err != nil {
-		return "", errors.Wrapf(err, "could not open file %s for hashing", filename)
+		return "", errors.WithMessagef(err, "could not open file %s for hashing", filename)
 	}
 	defer f.Close()
 	hash := fnv.New64a()
 	if _, err := io.Copy(hash, f); err != nil {
-		return "", errors.Wrapf(err, "could not hash file %s", filename)
+		return "", errors.WithMessagef(err, "could not hash file %s", filename)
 	}
 
 	return fmt.Sprintf(`W/"%x"`, hash.Sum(nil)), nil
@@ -102,7 +102,7 @@ func registerContentFiles(root string, log *log.Logger) error {
 		return nil
 	})
 	if err != nil {
-		return errors.Wrap(err, "could not walk directory")
+		return errors.WithMessage(err, "could not walk directory")
 	}
 
 	return nil