Files
marka/template/error.go
2025-09-26 17:32:16 +02:00

37 lines
602 B
Go

package template
import (
"fmt"
"strings"
)
type Error struct {
err error
start, end int
}
func (e Error) Error() string {
content := e.err.Error()
if strings.Contains(content, " @pos ") {
if e.start == e.end {
return strings.ReplaceAll(content, " @pos ", " ")
}
return strings.ReplaceAll(content, " @pos ", fmt.Sprintf(" position=%d:%d ", e.start, e.end))
}
return content
}
func NewErrorf(msg string, args ...any) Error {
return Error{
err: fmt.Errorf(msg, args...),
}
}
func (e Error) WithPosition(start, end int) Error {
e.start = start
e.end = end
return e
}