diff --git a/cmd/control/config.go b/cmd/control/config.go index 91d47f62..ee21aaa9 100644 --- a/cmd/control/config.go +++ b/cmd/control/config.go @@ -255,7 +255,7 @@ func validate(c *cli.Context) error { if err != nil { log.Fatal(err) } - validationErrors, err := config.Validate(bytes) + validationErrors, err := config.ValidateBytes(bytes) if err != nil { log.Fatal(err) } diff --git a/config/disk.go b/config/disk.go index 31df5a7f..9b351c29 100755 --- a/config/disk.go +++ b/config/disk.go @@ -71,8 +71,19 @@ func LoadConfigWithPrefix(dirPrefix string) *CloudConfig { cfg := &CloudConfig{} if err := util.Convert(rawCfg, cfg); err != nil { - log.Errorf("Failed to parse configuration: %s", err) + log.Errorf("EXITING: Failed to parse configuration: %s", err) log.Debugf("Bad cfg:\n%v\n", rawCfg) + // no point returning {}, it'll just sit there broken + // TODO: print some context around what failed.. + validationErrors, err := ValidateRawCfg(rawCfg) + if err != nil { + log.Fatal(err) + } + for _, validationError := range validationErrors.Errors() { + log.Error(validationError) + } + // TODO: I'd love to panic & recover(), for issues on boot, but it doesn't work yet + os.Exit(-1) return &CloudConfig{} } cfg = amendNils(cfg) diff --git a/config/validate.go b/config/validate.go index 142ec923..7f2c243b 100644 --- a/config/validate.go +++ b/config/validate.go @@ -31,11 +31,15 @@ func ConvertKeysToStrings(item interface{}) interface{} { } } -func Validate(bytes []byte) (*gojsonschema.Result, error) { +func ValidateBytes(bytes []byte) (*gojsonschema.Result, error) { var rawCfg map[string]interface{} if err := yaml.Unmarshal([]byte(bytes), &rawCfg); err != nil { return nil, err } + return ValidateRawCfg(rawCfg) +} + +func ValidateRawCfg(rawCfg interface{}) (*gojsonschema.Result, error) { rawCfg = ConvertKeysToStrings(rawCfg).(map[string]interface{}) loader := gojsonschema.NewGoLoader(rawCfg) schemaLoader := gojsonschema.NewStringLoader(schema) diff --git a/init/init.go b/init/init.go index f4825bee..5e83f2bf 100755 --- a/init/init.go +++ b/init/init.go @@ -94,6 +94,7 @@ func sysInit(c *config.CloudConfig) (*config.CloudConfig, error) { func MainInit() { log.InitDeferedLogger() + // TODO: this breaks and does nothing if the cfg is invalid (or is it due to threading?) defer func() { if r := recover(); r != nil { fmt.Printf("Starting Recovery console: %v\n", r)