1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00
goreleaser/internal/tmpl/errors.go
Carlos Alexandro Becker c91c4b7cd8
feat: improve template error handling (#4256)
- wrap the multiple errors in an internal error with cleaner messaging
- improve testlib.RequireTemplateError and several tests
2023-08-24 22:06:12 -03:00

46 lines
784 B
Go

package tmpl
import (
"fmt"
"regexp"
)
var res = []*regexp.Regexp{
regexp.MustCompile(`^template: tmpl:\d+:\d+: executing ".+" at .+: `),
regexp.MustCompile(`^template: tmpl:\d+:\d+: `),
regexp.MustCompile(`^template: tmpl:\d+: `),
}
func newTmplError(str string, err error) error {
if err == nil {
return nil
}
details := err.Error()
for _, re := range res {
if re.MatchString(details) {
details = re.ReplaceAllString(details, "")
break
}
}
return Error{str, details, err}
}
// Error is returned on any template error.
type Error struct {
str string
details string
err error
}
func (e Error) Unwrap() error {
return e.err
}
func (e Error) Error() string {
return fmt.Sprintf(
"template: failed to apply %q: %s",
e.str,
e.details,
)
}