Fix reflect panic in runtime/conversion

Fixes `panic: reflect: call of reflect.Value.Type on zero Value`
when calling conversion.EnforcePtr() or
runtime.Scheme.ObjectVersionAndKind() from default type switch.

Signed-off-by: Vojtech Vitek (V-Teq) <vvitek@redhat.com>
This commit is contained in:
Vojtech Vitek (V-Teq)
2014-10-27 07:46:42 +01:00
parent dc7e3d6601
commit 6a6f24b126
3 changed files with 29 additions and 1 deletions

View File

@@ -113,7 +113,10 @@ func UpdateVersionAndKind(baseFields []string, versionField, version, kindField,
func EnforcePtr(obj interface{}) (reflect.Value, error) {
v := reflect.ValueOf(obj)
if v.Kind() != reflect.Ptr {
return reflect.Value{}, fmt.Errorf("expected pointer, but got %v", v.Type().Name())
if v.Kind() == reflect.Invalid {
return reflect.Value{}, fmt.Errorf("expected pointer, but got invalid kind")
}
return reflect.Value{}, fmt.Errorf("expected pointer, but got %v type", v.Type().Name())
}
return v.Elem(), nil
}