github.com/EagleQL/Xray-core@v1.4.3/common/errors/multi_error.go (about)

     1  package errors
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  type multiError []error
     8  
     9  func (e multiError) Error() string {
    10  	var r strings.Builder
    11  	r.WriteString("multierr: ")
    12  	for _, err := range e {
    13  		r.WriteString(err.Error())
    14  		r.WriteString(" | ")
    15  	}
    16  	return r.String()
    17  }
    18  
    19  func Combine(maybeError ...error) error {
    20  	var errs multiError
    21  	for _, err := range maybeError {
    22  		if err != nil {
    23  			errs = append(errs, err)
    24  		}
    25  	}
    26  	if len(errs) == 0 {
    27  		return nil
    28  	}
    29  	return errs
    30  }