From d1405e4d50b4e886c5119f747842878b45ef5cdf Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Tue, 4 Nov 2014 02:12:02 -0800 Subject: [PATCH] fix(commands/request) cast safely should be able to look at a function in isolation and prove it won't panic. if that's not possible, should cast safely. --- commands/request.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/commands/request.go b/commands/request.go index c26f1773bc48..40eda9fc6fd5 100644 --- a/commands/request.go +++ b/commands/request.go @@ -1,6 +1,7 @@ package commands import ( + "errors" "fmt" "reflect" "strconv" @@ -116,7 +117,11 @@ func (r *request) ConvertOptions(options map[string]Option) error { if kind != opt.Type { if kind == String { convert := converters[opt.Type] - val, err := convert(v.(string)) + str, ok := v.(string) + if !ok { + return errors.New("cast error") + } + val, err := convert(str) if err != nil { return fmt.Errorf("Could not convert string value '%s' to type '%s'", v, opt.Type.String())