Skip to content

Commit

Permalink
Improve error message and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
outscale-toa committed Jun 21, 2024
1 parent 82a4d1b commit 6051b48
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
13 changes: 3 additions & 10 deletions builder/common/omi_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package common

import (
"fmt"
"log"

oscgo "github.com/outscale/osc-sdk-go/v2"
)
Expand Down Expand Up @@ -41,23 +40,17 @@ func (d *OmiFilterOptions) GetFilteredImage(params oscgo.ReadImagesRequest, oscc
params.Filters.AccountAliases = &oali
}

log.Printf("filters to pass to API are %#v", params.GetFilters().ImageIds)
log.Printf("Using OMI Filters %#v", params)

imageResp, _, err := oscconn.Api.ImageApi.ReadImages(oscconn.Auth).ReadImagesRequest(params).Execute()
if err != nil {
err := fmt.Errorf("Error querying OMI: %s", err)
return nil, err
return nil, fmt.Errorf("Error querying OMI: %s", err)
}

if len(imageResp.GetImages()) == 0 {
err := fmt.Errorf("No OMI was found matching filters: %#v", params)
return nil, err
return nil, fmt.Errorf("No OMI was found matching filters: %v", params.Filters.GetImageNames())
}

if len(imageResp.GetImages()) > 1 && !d.MostRecent {
err := fmt.Errorf("your query returned more than one result. Please try a more specific search, or set most_recent to true")
return nil, err
return nil, fmt.Errorf("your query returned more than one result. Please try a more specific search, or set most_recent to true")
}

var image oscgo.Image
Expand Down
2 changes: 1 addition & 1 deletion builder/common/step_source_omi_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *StepSourceOMIInfo) Run(_ context.Context, state multistep.StateBag) mul
}

if len(*imageResp.Images) == 0 {
err := fmt.Errorf("No OMI was found matching filters: %#v", params)
err := fmt.Errorf("No OMI was found matching filters: %v", params.Filters.GetImageNames())
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand Down

0 comments on commit 6051b48

Please sign in to comment.