mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-08 03:31:59 +02:00
c91c4b7cd8
- wrap the multiple errors in an internal error with cleaner messaging - improve testlib.RequireTemplateError and several tests
46 lines
784 B
Go
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,
|
|
)
|
|
}
|