From 414f94b7d1196342a4d795d380b670393a857a06 Mon Sep 17 00:00:00 2001 From: Evan Hazlett Date: Wed, 7 Jan 2015 13:26:53 -0800 Subject: [PATCH 1/2] add cleanup for create failure Signed-off-by: Evan Hazlett --- commands.go | 11 ++++++++++- host.go | 4 +--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/commands.go b/commands.go index ee6b9c5543..c713c0043d 100644 --- a/commands.go +++ b/commands.go @@ -190,7 +190,16 @@ func cmdCreate(c *cli.Context) { host, err := store.Create(name, driver, c) if err != nil { - log.Fatal(err) + log.Errorf("Error creating host: %s", err) + if c.GlobalBool("debug") { + log.Fatal(err) + } else { + log.Warnf("Removing provisioned machine. Use --debug to prevent removal.") + // we know there was an error so do not check for the error on removal + // instead we will Fatal with a message to prevent spamming with error messages + store.Remove(name, true) + log.Fatalf("You will want to check the provider to make sure the machine and associated resources were properly removed.") + } } if err := store.SetActive(host); err != nil { log.Fatalf("error setting active host: %v", err) diff --git a/host.go b/host.go index f2dd400060..58e534132d 100644 --- a/host.go +++ b/host.go @@ -227,9 +227,7 @@ func (h *Host) Upgrade() error { func (h *Host) Remove(force bool) error { if err := h.Driver.Remove(); err != nil { - if force { - log.Errorf("Error removing host, force removing anyway: %s", err) - } else { + if !force { return err } } From df5ecadf80d4bf680e0478414f1b74a042e683b0 Mon Sep 17 00:00:00 2001 From: Evan Hazlett Date: Wed, 7 Jan 2015 17:37:17 -0800 Subject: [PATCH 2/2] logging updates from @nathanleclaire Signed-off-by: Evan Hazlett --- commands.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/commands.go b/commands.go index c713c0043d..223d7baf1d 100644 --- a/commands.go +++ b/commands.go @@ -194,11 +194,12 @@ func cmdCreate(c *cli.Context) { if c.GlobalBool("debug") { log.Fatal(err) } else { - log.Warnf("Removing provisioned machine. Use --debug to prevent removal.") + log.Warnf("Removing created machine. You can run machine with the --debug flag to avoid this.") // we know there was an error so do not check for the error on removal // instead we will Fatal with a message to prevent spamming with error messages - store.Remove(name, true) - log.Fatalf("You will want to check the provider to make sure the machine and associated resources were properly removed.") + _ = store.Remove(name, true) + log.Warn("You will want to check the provider to make sure the machine and associated resources were properly removed.") + log.Fatal("Error creating machine") } } if err := store.SetActive(host); err != nil {