build: test LogError

Closes #34
This commit is contained in:
Michael McLoughlin
2019-01-06 13:52:32 -08:00
parent 07901bb91b
commit 7d20ff4ced
2 changed files with 77 additions and 1 deletions

View File

@@ -40,6 +40,10 @@ func (e *ErrorList) Add(err Error) {
*e = append(*e, err)
}
func (e *ErrorList) AddAt(p src.Position, err error) {
e.Add(Error{p, err})
}
// addext appends an error to the list, tagged with the
func (e *ErrorList) addext(err error) {
e.Add(exterr(err))
@@ -71,11 +75,11 @@ func (e ErrorList) Error() string {
func LogError(l *log.Logger, err error, max int) {
if list, ok := err.(ErrorList); ok {
for i, e := range list {
l.Printf("%s\n", e)
if max > 0 && i == max {
l.Print("too many errors")
return
}
l.Printf("%s\n", e)
}
} else if err != nil {
l.Printf("%s\n", err)