main: improve error handling when loading target/*.json
Этот коммит содержится в:
родитель
d7814ff50b
коммит
49b0086f8f
1 изменённых файлов: 17 добавлений и 10 удалений
|
@ -65,7 +65,7 @@ type TargetSpec struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// overrideProperties overrides all properties that are set in child into itself using reflection.
|
// overrideProperties overrides all properties that are set in child into itself using reflection.
|
||||||
func (spec *TargetSpec) overrideProperties(child *TargetSpec) {
|
func (spec *TargetSpec) overrideProperties(child *TargetSpec) error {
|
||||||
specType := reflect.TypeOf(spec).Elem()
|
specType := reflect.TypeOf(spec).Elem()
|
||||||
specValue := reflect.ValueOf(spec).Elem()
|
specValue := reflect.ValueOf(spec).Elem()
|
||||||
childValue := reflect.ValueOf(child).Elem()
|
childValue := reflect.ValueOf(child).Elem()
|
||||||
|
@ -95,14 +95,15 @@ func (spec *TargetSpec) overrideProperties(child *TargetSpec) {
|
||||||
for j := i + 1; j < dst.Len(); j++ {
|
for j := i + 1; j < dst.Len(); j++ {
|
||||||
w := dst.Index(j).String()
|
w := dst.Index(j).String()
|
||||||
if v == w {
|
if v == w {
|
||||||
panic("duplicate value '" + v + "' in field : " + field.Name)
|
return fmt.Errorf("duplicate value '" + v + "' in field : " + field.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
panic("unknown field type : " + kind.String())
|
return fmt.Errorf("unknown field type : " + kind.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// load reads a target specification from the JSON in the given io.Reader. It
|
// load reads a target specification from the JSON in the given io.Reader. It
|
||||||
|
@ -150,11 +151,17 @@ func (spec *TargetSpec) resolveInherits() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
newSpec.overrideProperties(subtarget)
|
err = newSpec.overrideProperties(subtarget)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When all properties are loaded, make sure they are properly inherited.
|
// When all properties are loaded, make sure they are properly inherited.
|
||||||
newSpec.overrideProperties(spec)
|
err := newSpec.overrideProperties(spec)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
*spec = *newSpec
|
*spec = *newSpec
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -221,7 +228,7 @@ func LoadTarget(options *Options) (*TargetSpec, error) {
|
||||||
// it includes all parents as specified in the "inherits" key.
|
// it includes all parents as specified in the "inherits" key.
|
||||||
err = spec.resolveInherits()
|
err = spec.resolveInherits()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("%s : %w", options.Target, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if spec.Scheduler == "asyncify" {
|
if spec.Scheduler == "asyncify" {
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче