diff options
author | LaMont Jones <lamontjones@google.com> | 2024-02-23 15:01:55 -0800 |
---|---|---|
committer | LaMont Jones <lamontjones@google.com> | 2024-02-23 15:04:04 -0800 |
commit | 89e90b4c60ab2d8f9c953bfcdf7876ab7da44545 (patch) | |
tree | 7dfb9196f54634505e83e32dff32af47145e9771 | |
parent | 5920e5507e7f6be48c24101db60693fa22d54990 (diff) | |
download | blueprint-89e90b4c60ab2d8f9c953bfcdf7876ab7da44545.tar.gz |
debugValue: handle Interfaces better.
Bug: none
Test: manual
Change-Id: Ic8ee668abf4387fc2f00e1f520efea360eebd66c
-rw-r--r-- | context.go | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -5010,8 +5010,10 @@ func debugKey(value reflect.Value) string { // Convert a single value (possibly a map or slice too) in a reflect.Value to a value suitable for outputting to json func debugValue(value reflect.Value) interface{} { + // Remember if we originally received a reflect.Interface. + wasInterface := value.Kind() == reflect.Interface // Dereference pointers down to the real type - for value.Kind() == reflect.Ptr { + for value.Kind() == reflect.Ptr || value.Kind() == reflect.Interface { // If it's nil, return nil if value.IsNil() { return nil @@ -5030,13 +5032,17 @@ func debugValue(value reflect.Value) interface{} { case reflect.Slice: return debugSlice(value) case reflect.Struct: + // If we originally received an interface, and there is a String() method, call that. + // TODO: figure out why Path doesn't work correctly otherwise (in aconfigPropagatingDeclarationsInfo) + if s, ok := value.Interface().(interface{ String() string }); wasInterface && ok { + return s.String() + } return debugStruct(value) case reflect.Map: return debugMap(value) - case reflect.Interface: - // ??? default: - // ??? + // TODO: add cases as we find them. + return fmt.Sprintf("debugValue(Kind=%v, wasInterface=%v)", kind, wasInterface) } return nil |