github.com/avahowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/build/errors.go (about)

     1  package build
     2  
     3  import (
     4  	"errors"
     5  	"strings"
     6  )
     7  
     8  // JoinErrors concatenates the elements of errs to create a single error. The
     9  // separator string sep is placed between elements in the resulting error. Nil
    10  // errors are skipped. If errs is empty or only contains nil elements,
    11  // JoinErrors returns nil.
    12  func JoinErrors(errs []error, sep string) error {
    13  	var strs []string
    14  	for _, err := range errs {
    15  		if err != nil {
    16  			strs = append(strs, err.Error())
    17  		}
    18  	}
    19  	if len(strs) > 0 {
    20  		return errors.New(strings.Join(strs, sep))
    21  	}
    22  	return nil
    23  }