Skip to content

Commit

Permalink
throw error instead of panic when replacements source.fieldPath doesn…
Browse files Browse the repository at this point in the history
…'t exist
  • Loading branch information
natasha41575 committed Sep 2, 2021
1 parent da05822 commit 68f70ef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
7 changes: 4 additions & 3 deletions api/filters/replacement/replacement.go
Expand Up @@ -131,10 +131,11 @@ func getReplacement(nodes []*yaml.RNode, r *types.Replacement) (*yaml.RNode, err
if err != nil {
return nil, err
}
if !rn.IsNilOrEmpty() {
return getRefinedValue(r.Source.Options, rn)
if rn.IsNilOrEmpty() {
return nil, fmt.Errorf("fieldPath `%s` is missing for replacement source %s", r.Source.FieldPath, r.Source)
}
return rn, nil

return getRefinedValue(r.Source.Options, rn)
}

func getRefinedValue(options *types.FieldOptions, rn *yaml.RNode) (*yaml.RNode, error) {
Expand Down
3 changes: 1 addition & 2 deletions api/filters/replacement/replacement_test.go
Expand Up @@ -1587,8 +1587,7 @@ data:
options:
create: true
`,
// this test currently panics instead of throwing an error
expectedErr: "fieldPath data.httpPort is missing for source ~G_~V_ConfigMap|~X|ports-from:data.httpPort",
expectedErr: "fieldPath `data.httpPort` is missing for replacement source ~G_~V_ConfigMap|~X|ports-from:data.httpPort",
},
}

Expand Down

0 comments on commit 68f70ef

Please sign in to comment.