@cryptotaxi247 / kubo / commits / c46d4c895

cmd2 fixed config panic

The way the current marshallers marshal out output requires a ton of error checking. I wish there was a way to have the library call our marshaller with the right type (rather than an interface). Maybe can do this with Reflect someday.

Juan Batiz-Benet committed Nov 12, 2014 at 17:51 UTC c46d4c8953cc632d7add162579cd00bbf8f7933b
1 file changed +11 -2
core/commands2/config.go
+11 -2
@@ -90,8 +90,17 @@ Set the value of the 'datastore.path' key:
90 return nil, nil // dont output anything
91 }
92
93 - v := res.Output().(*ConfigField)
94 - buf, err := config.HumanOutput(v.Value)
93 + v := res.Output()
94 + if v == nil {
95 + k := res.Request().Arguments()[0]
96 + return nil, fmt.Errorf("config does not contain key: %s", k)
97 + }
98 + vf, ok := v.(*ConfigField)
99 + if !ok {
100 + return nil, u.ErrCast()
101 + }
102 +
103 + buf, err := config.HumanOutput(vf.Value)
104 if err != nil {
105 return nil, err
106 }