1package openapi3 2 3import ( 4 "bytes" 5 "errors" 6) 7 8// MultiError is a collection of errors, intended for when 9// multiple issues need to be reported upstream 10type MultiError []error 11 12func (me MultiError) Error() string { 13 buff := &bytes.Buffer{} 14 for _, e := range me { 15 buff.WriteString(e.Error()) 16 buff.WriteString(" | ") 17 } 18 return buff.String() 19} 20 21//Is allows you to determine if a generic error is in fact a MultiError using `errors.Is()` 22//It will also return true if any of the contained errors match target 23func (me MultiError) Is(target error) bool { 24 if _, ok := target.(MultiError); ok { 25 return true 26 } 27 for _, e := range me { 28 if errors.Is(e, target) { 29 return true 30 } 31 } 32 return false 33} 34 35//As allows you to use `errors.As()` to set target to the first error within the multi error that matches the target type 36func (me MultiError) As(target interface{}) bool { 37 for _, e := range me { 38 if errors.As(e, target) { 39 return true 40 } 41 } 42 return false 43} 44