Skip to content

Commit

Permalink
fix(commands/request) cast safely
Browse files Browse the repository at this point in the history
should be able to look at a function in isolation and prove it won't
panic. if that's not possible, should cast safely.
  • Loading branch information
Brian Tiger Chow committed Nov 4, 2014
1 parent 8eaa405 commit d1405e4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion commands/request.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package commands

import (
"errors"
"fmt"
"reflect"
"strconv"
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit d1405e4

Please sign in to comment.