Fix race with context shutdown and error message printing.

This commit is contained in:
Andrey Smirnov
2014-03-07 17:23:56 +04:00
parent 57722597ee
commit 1571a3331d
+11 -3
View File
@@ -9,10 +9,13 @@ import (
"path/filepath"
)
var returnCode = 0
var (
returnCode = 0
errorMessage string
)
func fatal(err error) {
fmt.Printf("ERROR: %s\n", err)
errorMessage = fmt.Sprintf("ERROR: %s\n", err)
returnCode = 1
}
@@ -53,7 +56,12 @@ func loadConfig(command *commander.Command) error {
}
func main() {
defer func() { os.Exit(returnCode) }()
defer func() {
if errorMessage != "" {
fmt.Print(errorMessage)
}
os.Exit(returnCode)
}()
command := cmd.RootCommand()