Correctly fail if no Image matches filter

This commit is contained in:
Rickard von Essen 2018-08-21 12:46:42 +02:00
parent c5fe1e9e34
commit bd1961b927
1 changed files with 9 additions and 4 deletions

View File

@ -38,15 +38,13 @@ func (s *StepSourceImageInfo) Run(_ context.Context, state multistep.StateBag) m
}
switch len(i) {
case 0:
return false, fmt.Errorf("No image was found matching filters: %v", s.SourceImageOpts)
case 1:
*image = i[0]
return true, nil
return false, nil
default:
if s.SourceMostRecent {
*image = i[0]
return true, nil
return false, nil
}
return false, fmt.Errorf(
"Your query returned more than one result. Please try a more specific search, or set most_recent to true. Search filters: %v",
@ -54,6 +52,13 @@ func (s *StepSourceImageInfo) Run(_ context.Context, state multistep.StateBag) m
}
})
if image.ID == "" {
err := fmt.Errorf("No image was found matching filters: %v", s.SourceImageOpts)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
if err != nil {
err := fmt.Errorf("Error querying image: %s", err)
state.Put("error", err)