Skip to content

Commit 8aca876

Browse files
authored
HCP: error handling & empty source image id (#90)
* 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
1 parent fa16666 commit 8aca876

1 file changed

Lines changed: 0 additions & 21 deletions

File tree

packer/registry/image/image.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ func (i *Image) Validate() error {
5050
return errors.New("error registry image does not contain a valid ProviderName")
5151
}
5252

53-
if i.SourceImageID == "" {
54-
return errors.New("error registry image does not contain a valid SourceImageID")
55-
}
56-
5753
return nil
5854
}
5955

@@ -70,7 +66,6 @@ func (i *Image) String() string {
7066
// calling f(k,v). The func f is responsible for type asserting the expected type for the key and value before
7167
// trying to create an Image from it.
7268
func FromMappedData(mappedData interface{}, f func(key, value interface{}) (*Image, error)) ([]*Image, error) {
73-
7469
mapValue := reflect.ValueOf(mappedData)
7570
if mapValue.Kind() != reflect.Map {
7671
return nil, errors.New("error the incoming mappedData does not appear to be a map; found type to be" + mapValue.Kind().String())
@@ -118,10 +113,6 @@ func FromArtifact(a packer.Artifact, opts ...ArtifactOverrideFunc) (*Image, erro
118113
// used to override the ProviderName for an existing Image.
119114
func WithProvider(name string) func(*Image) error {
120115
return func(img *Image) error {
121-
if img == nil {
122-
return errors.New("no go on empty image")
123-
}
124-
125116
img.ProviderName = name
126117
return nil
127118
}
@@ -131,10 +122,6 @@ func WithProvider(name string) func(*Image) error {
131122
// used to override the ImageId for an existing Image.
132123
func WithID(id string) func(*Image) error {
133124
return func(img *Image) error {
134-
if img == nil {
135-
return errors.New("no go on empty image")
136-
}
137-
138125
img.ImageID = id
139126
return nil
140127
}
@@ -144,10 +131,6 @@ func WithID(id string) func(*Image) error {
144131
// used to override the SourceImageId for an existing Image.
145132
func WithSourceID(id string) func(*Image) error {
146133
return func(img *Image) error {
147-
if img == nil {
148-
return errors.New("no go on empty image")
149-
}
150-
151134
img.SourceImageID = id
152135
return nil
153136
}
@@ -157,10 +140,6 @@ func WithSourceID(id string) func(*Image) error {
157140
// used to override the ProviderRegion for an existing Image.
158141
func WithRegion(region string) func(*Image) error {
159142
return func(img *Image) error {
160-
if img == nil {
161-
return errors.New("no go on empty image")
162-
}
163-
164143
img.ProviderRegion = region
165144
return nil
166145
}

0 commit comments

Comments
 (0)