From 4067bab3d415e2417a959ff1357f8ab0717aeb2a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 4 Oct 2013 10:44:04 -0700 Subject: [PATCH] builder/digitalocean: don't panic if error contains no message [GH-492] --- CHANGELOG.md | 2 ++ builder/digitalocean/api.go | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cc95e4fd..cf62f1129 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ BUG FIXES: * builder/all: timeout waiting for SSH connection is a failure. [GH-491] +* builder/digitalocean: don't panic if erroneous API response doesn't + contain error message. [GH-492] * builder/virtualbox: error if VirtualBox version cant be detected. [GH-488] * builder/virtualbox: detect if vboxdrv isn't properly setup. [GH-488] diff --git a/builder/digitalocean/api.go b/builder/digitalocean/api.go index 7e09595cc..b22c1bb4d 100644 --- a/builder/digitalocean/api.go +++ b/builder/digitalocean/api.go @@ -227,7 +227,13 @@ func NewRequest(d DigitalOceanClient, path string, params url.Values) (map[strin } if status == "ERROR" { - status = decodedResponse["message"].(string) + statusRaw, ok := decodedResponse["message"] + if ok { + status = statusRaw.(string) + } else { + status = fmt.Sprintf( + "Unknown error. Full response body: %s", body) + } } lastErr = errors.New(fmt.Sprintf("Received error from DigitalOcean (%d): %s",