jackhammer

Utilities for Go
Log | Files | Refs | README | LICENSE

errorsx.go (431B)


      1 package errorsx
      2 
      3 import (
      4 	"strings"
      5 )
      6 
      7 type PolyError struct {
      8 	Errs []error
      9 }
     10 
     11 func (err PolyError) Unwrap() []error {
     12 	return err.Errs
     13 }
     14 
     15 func (err PolyError) Error() string {
     16 	var b strings.Builder
     17 	b.WriteString("multiple errors:\n")
     18 	for ii, e := range err.Errs {
     19 		if e == nil {
     20 			continue
     21 		}
     22 		b.WriteString("  - ")
     23 		b.WriteString(e.Error())
     24 		if ii != len(err.Errs)-1 {
     25 			b.WriteByte('\n')
     26 		}
     27 	}
     28 	return b.String()
     29 }