The problem is that the value passed to the channel as an error interface is not nil , but rather an exec.Error pointer that points to nil.
The program will behave correctly if you change:
go func() { var e *exec.Error = nil if e == nil { errChan <- nil } }()
This is an appropriate way to solve the problem, because the idiomatic way of reporting that an error has not occurred is to pass the nil error interface.
However, if you want to change the main one instead (perhaps because you are using a third-party package that makes the error returning pointers equal to zero), you will either have to execute a type statement for a specific type (* exec.Error), and then check to see if he or not, or use the reflection package.
An example of using a reflex to check for zero:
func IsNil(i interface{}) bool { // Check if it is an actual nil-value if i == nil { return true } v := reflect.ValueOf(i) switch v.Kind() { // Only the following kinds can be nil case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: return v.IsNil() } return false }
Working example: http://play.golang.org/p/rpG1PVTwwM
You can find out about it here: https://groups.google.com/forum/#!topic/golang-nuts/QzVDKv7p0Vs
Anisus
source share