From 6593491d14fca995750f4e3f06b7843316c15379 Mon Sep 17 00:00:00 2001 From: Elliot Date: Wed, 21 Aug 2019 19:20:45 -0700 Subject: [PATCH] Handle error case when no instances returned Handle the error case that can arise when requests to run new AWS instances returns no errors but an empty struct of results. Signed-off-by: erushton --- drivers/amazonec2/amazonec2.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/amazonec2/amazonec2.go b/drivers/amazonec2/amazonec2.go index b7704ad9d8..a446ab7639 100644 --- a/drivers/amazonec2/amazonec2.go +++ b/drivers/amazonec2/amazonec2.go @@ -664,7 +664,10 @@ func (d *Driver) innerCreate() error { spotInstanceRequest, err := d.getClient().RequestSpotInstances(&req) if err != nil { - return fmt.Errorf("Error request spot instance: %s", err) + return fmt.Errorf("Error request spot instance: %v", err) + } + if spotInstanceRequest == nil || len((*spotInstanceRequest).SpotInstanceRequests) < 1 { + return fmt.Errorf("Error requesting spot instance: %v", errors.New("Unexpected AWS API response")) } d.spotInstanceRequestId = *spotInstanceRequest.SpotInstanceRequests[0].SpotInstanceRequestId @@ -740,7 +743,10 @@ func (d *Driver) innerCreate() error { }) if err != nil { - return fmt.Errorf("Error launching instance: %s", err) + return fmt.Errorf("Error launching instance: %v", err) + } + if inst == nil || len(inst.Instances) < 1 { + return fmt.Errorf("Error launching instance: %v", errors.New("Unexpected AWS API response")) } instance = inst.Instances[0] }