wrap.go raw

   1  package errd
   2  
   3  import (
   4  	"fmt"
   5  )
   6  
   7  // Wrap wraps err with fmt.Errorf if err is non nil.
   8  // Intended for use with defer and a named error return.
   9  // Inspired by https://github.com/golang/go/issues/32676.
  10  func Wrap(err *error, f string, v ...interface{}) {
  11  	if *err != nil {
  12  		*err = fmt.Errorf(f+": %w", append(v, *err)...)
  13  	}
  14  }
  15