mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 02:30:39 +08:00
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.
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -116,7 +117,11 @@ func (r *request) ConvertOptions(options map[string]Option) error {
|
|||||||
if kind != opt.Type {
|
if kind != opt.Type {
|
||||||
if kind == String {
|
if kind == String {
|
||||||
convert := converters[opt.Type]
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("Could not convert string value '%s' to type '%s'",
|
return fmt.Errorf("Could not convert string value '%s' to type '%s'",
|
||||||
v, opt.Type.String())
|
v, opt.Type.String())
|
||||||
|
Reference in New Issue
Block a user