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 59c269a commit 5216bf1
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

1 comment on commit 5216bf1

@jbenet
Copy link
Member

@jbenet jbenet commented on 5216bf1 Nov 4, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mappum note this commit's log. +100000

Please sign in to comment.