Skip to content

Commit

Permalink
fix: show error instead of crashing on descriptor deserialization error
Browse files Browse the repository at this point in the history
  • Loading branch information
metacosm committed Apr 6, 2020
1 parent e7739c1 commit 753005f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pkg/cmdutil/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
halkyon "halkyon.io/api"
capability "halkyon.io/api/capability/v1beta1"
component "halkyon.io/api/component/v1beta1"
"halkyon.io/hal/pkg/ui"
"io/ioutil"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -121,15 +122,21 @@ func (hd *HalkyonDescriptor) addEntitiesFromDir(path string) {
extensions := []string{"yaml", "yml"}
for _, extension := range extensions {
hdPath := filepath.Join(path, descriptorName(extension))
d, _ := LoadHalkyonDescriptor(hdPath)
hd.mergeWith(d)
hd.loadDescriptorAt(hdPath)

hdPath = halkyonDescriptorFrom(path, extension)
fromDekorate, _ := LoadHalkyonDescriptor(hdPath)
hd.mergeWith(fromDekorate)
hd.loadDescriptorAt(hdPath)
}
}

func (hd *HalkyonDescriptor) loadDescriptorAt(hdPath string) {
fromDekorate, e := LoadHalkyonDescriptor(hdPath)
if e != nil && !os.IsNotExist(e) {
ui.OutputError(fmt.Sprintf("Ignoring %s due to error: %v", hdPath, e))
}
hd.mergeWith(fromDekorate)
}

func LoadHalkyonDescriptor(descriptor string) (*HalkyonDescriptor, error) {
// look for the component name in the halkyon descriptor
file, err := os.Open(descriptor)
Expand All @@ -148,7 +155,7 @@ func LoadHalkyonDescriptor(descriptor string) (*HalkyonDescriptor, error) {
if object == nil {
object, _, err = deserializer.Decode(value.Raw, nil, nil)
if err != nil {
return nil, err
return newHalkyonDescriptor(0), err
}
}

Expand Down

0 comments on commit 753005f

Please sign in to comment.