Skip to content

Commit

Permalink
Issue #337 Remove rerr = nil from the defer function
Browse files Browse the repository at this point in the history
Current code for handling error in the configureCluster function is wrong
and return nil even there is an error because of the way we handled in the
defer function.

Following snip will always return the `nil` since it is assigned to `nil`
at the end of defer function.

```
package main

import (
        "fmt"
)

func getError() (rerr error) {
        defer func(){
                err := fmt.Errorf("Error from defer")
                if err != nil {
                    rerr = err
                }
                rerr = nil
        }()
        return fmt.Errorf("My error should be returned")
}

func main() {
        fmt.Println(getError())
}
```
  • Loading branch information
praveenkumar committed Dec 14, 2019
1 parent 71de1a1 commit 2afc821
Showing 1 changed file with 0 additions and 1 deletion.
1 change: 0 additions & 1 deletion pkg/crc/machine/machine.go
Expand Up @@ -694,7 +694,6 @@ func configureCluster(ocConfig oc.OcConfig, sshRunner *crcssh.SSHRunner, pullSec
if err := cluster.StopAndRemovePodsInVM(sshRunner); err != nil {
rerr = err
}
rerr = nil
}()

logging.Info("Adding user's pull secret ...")
Expand Down

0 comments on commit 2afc821

Please sign in to comment.