title: Go reflect. How to check whether reflect.Type is an error type?
body: <p>I need to assuredly check whether a reflect.Type is an error. </p>
  
  <p>There is no reflect kind for error. What is the formal/idiomatic manner to check for type error in go reflect?</p>
  
  <p><a href="http://play.golang.org/p/JbECG4dvAm" rel="noreferrer">Go Playground Full Example</a></p>
  
  <pre><code>//return map of default values, based on each return type of a function
  // error  =&gt; err=nil
  // bool   =&gt; true
  // struct =&gt; new struct
  func getDefaultValue(originalFunction interface{}) map[int]reflect.Value {
      defaultValues := make(map[int]reflect.Value)
  
      typeOfFunc := reflect.ValueOf(originalFunction).Type()
  
      numOut := typeOfFunc.NumOut() //number of function returns
  
      for i := 0; i &lt; numOut; i++ {
  
          typeOut := typeOfFunc.Out(i) // type of return for index i
          switch typeOut.Kind() {
  
          case reflect.Bool:
              defaultValues[i] = reflect.ValueOf(true)
  
          case reflect.Struct:
              defaultValues[i] = reflect.New(typeOut()).Elem()
  
          // --&gt; How to identify reflect.Type error assuredly, using switch or if...
          //case reflect.error: //don't exists
          //  var err error = nil
          //  defaultValues[i] = reflect.ValueOf(&amp;err).Elem()
  
          default:
              //var err error = nil
              //defaultValues[i] = reflect.ValueOf(&amp;err).Elem()
              fmt.Println("type of return index ", i, " was not identified")
  
          }
  
          fmt.Println("type of return index ", i, typeOut, "kind", typeOut.Kind(), "assign to err ", typeOut.AssignableTo(reflect.TypeOf(errors.New(""))))
      }
  
      return defaultValues
  }
  </code></pre>