Skip to content

Commit

Permalink
ensure sync doesn't panic when given invalid or empty yaml content
Browse files Browse the repository at this point in the history
  • Loading branch information
joshrwolf committed Dec 11, 2021
1 parent d2d3183 commit d31a17f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cmd/hauler/cli/store/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func SyncCmd(ctx context.Context, o *SyncOpts, s *store.Store) error {
for _, doc := range docs {
obj, err := content.Load(doc)
if err != nil {
return err
l.Debugf("skipping sync of unknown content")
continue
}

l.Infof("syncing [%s] to store", obj.GroupVersionKind().String())
Expand Down
4 changes: 2 additions & 2 deletions pkg/content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func Load(data []byte) (schema.ObjectKind, error) {
var tm *metav1.TypeMeta
var tm metav1.TypeMeta
if err := yaml.Unmarshal(data, &tm); err != nil {
return nil, err
}
Expand All @@ -20,5 +20,5 @@ func Load(data []byte) (schema.ObjectKind, error) {
return nil, fmt.Errorf("unrecognized content/collection type: %s", tm.GroupVersionKind().String())
}

return tm, nil
return &tm, nil
}

0 comments on commit d31a17f

Please sign in to comment.