mirror of
https://github.com/rancher/os.git
synced 2025-08-31 06:11:12 +00:00
Tell the user if the interpreted cloud confg is invalid and then exit
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user