PKGBUILD/pkg/internal/errutils/errutils.go

32 lines
502 B
Go
Raw Normal View History

2019-02-24 21:46:36 +00:00
package errutils
import (
"fmt"
)
func CollectErrors(errChan <-chan error) []error {
errorList := make([]error, 0)
for {
select {
case err, more := <-errChan:
if more {
errorList = append(errorList, err)
continue
}
default:
return errorList
}
}
}
func FormatErrors(errorList []error) error {
if len(errorList) > 0 {
errMsg := ""
for _, err := range errorList {
errMsg = fmt.Sprintf("%v\n%v", errMsg, err.Error())
}
return fmt.Errorf(errMsg)
}
return nil
}