Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 8e4a758

Browse files
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.
1 parent a555e4f commit 8e4a758

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/amazonec2/amazonec2.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,10 @@ func (d *Driver) innerCreate() error {
664664

665665
spotInstanceRequest, err := d.getClient().RequestSpotInstances(&req)
666666
if err != nil {
667-
return fmt.Errorf("Error request spot instance: %s", err)
667+
return fmt.Errorf("Error request spot instance: %v", err)
668+
}
669+
if spotInstanceRequest == nil || len((*spotInstanceRequest).SpotInstanceRequests) < 1 {
670+
return fmt.Errorf("Error requesting spot instance: %v", errors.New("Unexpected AWS API response"))
668671
}
669672
d.spotInstanceRequestId = *spotInstanceRequest.SpotInstanceRequests[0].SpotInstanceRequestId
670673

@@ -740,7 +743,10 @@ func (d *Driver) innerCreate() error {
740743
})
741744

742745
if err != nil {
743-
return fmt.Errorf("Error launching instance: %s", err)
746+
return fmt.Errorf("Error launching instance: %v", err)
747+
}
748+
if inst == nil || len(inst.Instances) < 1 {
749+
return fmt.Errorf("Error launching instance: %v", errors.New("Unexpected AWS API response"))
744750
}
745751
instance = inst.Instances[0]
746752
}

0 commit comments

Comments
 (0)