You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cfg.Unpack panics under certain circumstances for structs that contain attributes of type map[string]interface{}. When unpacking a configuration that does not contain values for the attribute of type map into a a variable that already has data set for the map attribute, the cfg.Unpack panics with following error:
panic: reflect: call of reflect.Value.MapKeys on interface Value [recovered]
panic: reflect: call of reflect.Value.MapKeys on interface Value
How to reproduce
type Deployment struct {
Configurations []map[string]interface{} `config:"configurations"`
}
func TestUnpack(t *testing.T) {
var deployment Deployment
// unpack empty config into empty struct
cfg, _ := json.NewConfig([]byte(`{}`))
require.NoError(t, cfg.Unpack(&deployment))
fmt.Println(deployment)
// unpack config into empty struct
cfg, _ = json.NewConfig([]byte(`{"configurations":[{"name":"foo","body":{"env":{"v":1}}}]}`))
require.NoError(t, cfg.Unpack(&deployment))
fmt.Println(deployment)
// unpack config into struct with existing data
cfg, _ = json.NewConfig([]byte(`{"configurations":[{"name":"bar","body":{"env":{"v":1}}}]}`))
require.NoError(t, cfg.Unpack(&deployment))
fmt.Println(deployment)
// unpack empty config into struct with existing data
// panics
cfg, _ = json.NewConfig([]byte(`{}`))
require.NoError(t, cfg.Unpack(&deployment))
fmt.Println(deployment)
}
The text was updated successfully, but these errors were encountered:
Summary
cfg.Unpack
panics under certain circumstances for structs that contain attributes of typemap[string]interface{}
. When unpacking a configuration that does not contain values for the attribute of typemap
into a a variable that already has data set for themap
attribute, thecfg.Unpack
panics with following error:How to reproduce
The text was updated successfully, but these errors were encountered: