提交 de170927 作者: Brian Tiger Chow

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.
上级 d3f9aadd
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())
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论