Skip to content

Commit

Permalink
HCP: error handling & empty source image id (#90)
Browse files Browse the repository at this point in the history
* this error is mainly ignored, and I think it would be better to panic in this case

* don't error if no source image id was not passed
  • Loading branch information
azr authored Dec 16, 2021
1 parent fa16666 commit 8aca876
Showing 1 changed file with 0 additions and 21 deletions.
21 changes: 0 additions & 21 deletions packer/registry/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ func (i *Image) Validate() error {
return errors.New("error registry image does not contain a valid ProviderName")
}

if i.SourceImageID == "" {
return errors.New("error registry image does not contain a valid SourceImageID")
}

return nil
}

Expand All @@ -70,7 +66,6 @@ func (i *Image) String() string {
// calling f(k,v). The func f is responsible for type asserting the expected type for the key and value before
// trying to create an Image from it.
func FromMappedData(mappedData interface{}, f func(key, value interface{}) (*Image, error)) ([]*Image, error) {

mapValue := reflect.ValueOf(mappedData)
if mapValue.Kind() != reflect.Map {
return nil, errors.New("error the incoming mappedData does not appear to be a map; found type to be" + mapValue.Kind().String())
Expand Down Expand Up @@ -118,10 +113,6 @@ func FromArtifact(a packer.Artifact, opts ...ArtifactOverrideFunc) (*Image, erro
// used to override the ProviderName for an existing Image.
func WithProvider(name string) func(*Image) error {
return func(img *Image) error {
if img == nil {
return errors.New("no go on empty image")
}

img.ProviderName = name
return nil
}
Expand All @@ -131,10 +122,6 @@ func WithProvider(name string) func(*Image) error {
// used to override the ImageId for an existing Image.
func WithID(id string) func(*Image) error {
return func(img *Image) error {
if img == nil {
return errors.New("no go on empty image")
}

img.ImageID = id
return nil
}
Expand All @@ -144,10 +131,6 @@ func WithID(id string) func(*Image) error {
// used to override the SourceImageId for an existing Image.
func WithSourceID(id string) func(*Image) error {
return func(img *Image) error {
if img == nil {
return errors.New("no go on empty image")
}

img.SourceImageID = id
return nil
}
Expand All @@ -157,10 +140,6 @@ func WithSourceID(id string) func(*Image) error {
// used to override the ProviderRegion for an existing Image.
func WithRegion(region string) func(*Image) error {
return func(img *Image) error {
if img == nil {
return errors.New("no go on empty image")
}

img.ProviderRegion = region
return nil
}
Expand Down

0 comments on commit 8aca876

Please sign in to comment.