@cryptotaxi247 / kubo / commits / de170927a

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.

Brian Tiger Chow committed Nov 4, 2014 at 02:12 UTC de170927adb790b9c4fe234fd253bcbd0144c58a
1 file changed +6 -1
commands/request.go
+6 -1
@@ -1,6 +1,7 @@
1 package commands
2
3 import (
4 + "errors"
5 "fmt"
6 "reflect"
7 "strconv"
@@ -116,7 +117,11 @@ func (r *request) ConvertOptions(options map[string]Option) error {
117 if kind != opt.Type {
118 if kind == String {
119 convert := converters[opt.Type]
119 - val, err := convert(v.(string))
120 + str, ok := v.(string)
121 + if !ok {
122 + return errors.New("cast error")
123 + }
124 + val, err := convert(str)
125 if err != nil {
126 return fmt.Errorf("Could not convert string value '%s' to type '%s'",
127 v, opt.Type.String())