Skip to content

Commit 1b78f81

Browse files
andriygmjmwoliver
authored andcommitted
Return an error when getting header attributes for invalid header version
1 parent ee2fc60 commit 1b78f81

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

internal/distributions/distribution.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,13 @@ type BaseDistribution struct {
177177
Dynamic []string `json:"dynamic"`
178178
}
179179

180-
func (bd *BaseDistribution) GetHeaderAttrs() []HeaderAttr {
180+
func (bd *BaseDistribution) GetHeaderAttrs() ([]HeaderAttr, error) {
181181
ha, exists := HeaderAttrs[bd.MetadataVersion]
182-
if exists {
183-
return ha
182+
if !exists {
183+
return []HeaderAttr{}, fmt.Errorf("header attributes for metadata version %s not found", bd.MetadataVersion)
184184
}
185-
return []HeaderAttr{}
185+
186+
return ha, nil
186187
}
187188

188189
func (bd *BaseDistribution) Parse(data []byte) error {
@@ -200,7 +201,12 @@ func (bd *BaseDistribution) Parse(data []byte) error {
200201
bd.MetadataVersion = headerValue
201202
}
202203

203-
for _, headerAttr := range bd.GetHeaderAttrs() {
204+
headerAttrs, err := bd.GetHeaderAttrs()
205+
if err != nil {
206+
return err
207+
}
208+
209+
for _, headerAttr := range headerAttrs {
204210
if headerAttr.AttrName == "metadata_version" {
205211
continue
206212
}

0 commit comments

Comments
 (0)