From c46d4c8953cc632d7add162579cd00bbf8f7933b Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Wed, 12 Nov 2014 17:51:57 -0800 Subject: [PATCH] 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. --- core/commands2/config.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core/commands2/config.go b/core/commands2/config.go index d49d73c7a..2b26f509a 100644 --- a/core/commands2/config.go +++ b/core/commands2/config.go @@ -90,8 +90,17 @@ Set the value of the 'datastore.path' key: return nil, nil // dont output anything } - v := res.Output().(*ConfigField) - buf, err := config.HumanOutput(v.Value) + v := res.Output() + if v == nil { + k := res.Request().Arguments()[0] + return nil, fmt.Errorf("config does not contain key: %s", k) + } + vf, ok := v.(*ConfigField) + if !ok { + return nil, u.ErrCast() + } + + buf, err := config.HumanOutput(vf.Value) if err != nil { return nil, err }