Merge pull request #2774 from jeanlaurent/log-fatal-is-evil

log.fatal is evil
This commit is contained in:
David Gageot 2016-01-07 12:44:41 +01:00
commit dd67c30838
6 changed files with 14 additions and 31 deletions

View File

@ -204,11 +204,12 @@ func runDriver(driverName string) {
} }
func cmdNotFound(c *cli.Context, command string) { func cmdNotFound(c *cli.Context, command string) {
log.Fatalf( log.Errorf(
"%s: '%s' is not a %s command. See '%s --help'.", "%s: '%s' is not a %s command. See '%s --help'.",
c.App.Name, c.App.Name,
command, command,
c.App.Name, c.App.Name,
os.Args[0], os.Args[0],
) )
os.Exit(1)
} }

View File

@ -312,8 +312,8 @@ func matchesName(host *host.Host, names []string) bool {
for _, n := range names { for _, n := range names {
r, err := regexp.Compile(n) r, err := regexp.Compile(n)
if err != nil { if err != nil {
// TODO: remove that call to Fatal log.Error(err)
log.Fatal(err) os.Exit(1) // TODO: Can we get rid of this call, and exit 'properly' ?
} }
if r.MatchString(host.Driver.GetMachineName()) { if r.MatchString(host.Driver.GetMachineName()) {
return true return true

View File

@ -25,29 +25,34 @@ func main() {
data, err := json.Marshal(driver) data, err := json.Marshal(driver)
if err != nil { if err != nil {
log.Fatal(err) log.Error(err)
return
} }
h, err := client.NewHost("virtualbox", data) h, err := client.NewHost("virtualbox", data)
if err != nil { if err != nil {
log.Fatal(err) log.Error(err)
return
} }
h.HostOptions.EngineOptions.StorageDriver = "overlay" h.HostOptions.EngineOptions.StorageDriver = "overlay"
if err := client.Create(h); err != nil { if err := client.Create(h); err != nil {
log.Fatal(err) log.Error(err)
return
} }
out, err := h.RunSSHCommand("df -h") out, err := h.RunSSHCommand("df -h")
if err != nil { if err != nil {
log.Fatal(err) log.Error(err)
return
} }
fmt.Printf("Results of your disk space query:\n%s\n", out) fmt.Printf("Results of your disk space query:\n%s\n", out)
fmt.Println("Powering down machine now...") fmt.Println("Powering down machine now...")
if err := h.Stop(); err != nil { if err := h.Stop(); err != nil {
log.Fatal(err) log.Error(err)
return
} }
} }

View File

@ -69,18 +69,6 @@ func (ml *FmtMachineLogger) Infof(fmtString string, args ...interface{}) {
fmt.Fprintf(ml.outWriter, fmtString+"\n", args...) fmt.Fprintf(ml.outWriter, fmtString+"\n", args...)
} }
func (ml *FmtMachineLogger) Fatal(args ...interface{}) {
ml.history.Record(args...)
fmt.Fprintln(ml.errWriter, args...)
os.Exit(1)
}
func (ml *FmtMachineLogger) Fatalf(fmtString string, args ...interface{}) {
ml.history.Recordf(fmtString, args...)
fmt.Fprintf(ml.errWriter, fmtString+"\n", args...)
os.Exit(1)
}
func (ml *FmtMachineLogger) Warn(args ...interface{}) { func (ml *FmtMachineLogger) Warn(args ...interface{}) {
ml.history.Record(args...) ml.history.Record(args...)
fmt.Fprintln(ml.outWriter, args...) fmt.Fprintln(ml.outWriter, args...)

View File

@ -49,14 +49,6 @@ func Infof(fmtString string, args ...interface{}) {
logger.Infof(fmtString, args...) logger.Infof(fmtString, args...)
} }
func Fatal(args ...interface{}) {
logger.Fatal(args...)
}
func Fatalf(fmtString string, args ...interface{}) {
logger.Fatalf(fmtString, args...)
}
func Warn(args ...interface{}) { func Warn(args ...interface{}) {
logger.Warn(args...) logger.Warn(args...)
} }

View File

@ -17,9 +17,6 @@ type MachineLogger interface {
Info(args ...interface{}) Info(args ...interface{})
Infof(fmtString string, args ...interface{}) Infof(fmtString string, args ...interface{})
Fatal(args ...interface{})
Fatalf(fmtString string, args ...interface{})
Warn(args ...interface{}) Warn(args ...interface{})
Warnf(fmtString string, args ...interface{}) Warnf(fmtString string, args ...interface{})