From f99797eba3c584aaed5bcb7a0d96cedc2ad1413c Mon Sep 17 00:00:00 2001 From: Mark Peek Date: Wed, 31 Jul 2013 14:20:25 -0700 Subject: [PATCH] Handle missing source AMI error Specifying a non-existent source AMI will result in an empty array of images in the response which would cause an "index out of range" panic. This change handles this case more gracefully with an error message. --- builder/amazon/common/step_run_source_instance.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/builder/amazon/common/step_run_source_instance.go b/builder/amazon/common/step_run_source_instance.go index de91a1446..2c86e0d06 100644 --- a/builder/amazon/common/step_run_source_instance.go +++ b/builder/amazon/common/step_run_source_instance.go @@ -41,6 +41,10 @@ func (s *StepRunSourceInstance) Run(state map[string]interface{}) multistep.Step state["error"] = fmt.Errorf("There was a problem with the source AMI: %s", err) return multistep.ActionHalt } + if len(imageResp.Images) != 1 { + state["error"] = fmt.Errorf("The source AMI '%s' could not be found.", s.SourceAMI) + return multistep.ActionHalt + } if s.ExpectedRootDevice != "" && imageResp.Images[0].RootDeviceType != s.ExpectedRootDevice { state["error"] = fmt.Errorf(