fix(add) cast safely
Brian Tiger Chow committed
Nov 7, 2014 at 05:47 UTC
c65b01c55cd770177a7377e11cb2406445f7f0c5
2 files changed
+10
-6
cmd/ipfs2/daemon.go
+1
-1
@@ -9,7 +9,7 @@ import (
9
10
cmds "github.com/jbenet/go-ipfs/commands"
11
cmdsHttp "github.com/jbenet/go-ipfs/commands/http"
12
- "github.com/jbenet/go-ipfs/core"
12
+ core "github.com/jbenet/go-ipfs/core"
13
commands "github.com/jbenet/go-ipfs/core/commands2"
14
daemon "github.com/jbenet/go-ipfs/daemon2"
15
)
core/commands2/add.go
+9
-5
@@ -62,14 +62,18 @@ var addCmd = &cmds.Command{
62
},
63
Marshallers: map[cmds.EncodingType]cmds.Marshaller{
64
cmds.Text: func(res cmds.Response) ([]byte, error) {
65
- v := res.Output().(*AddOutput).Added
66
- if len(v) == 1 {
67
- s := fmt.Sprintf("Added object: %s\n", v[0].Hash)
65
+ val, ok := res.Output().(*AddOutput)
66
+ if !ok {
67
+ return nil, errors.New("cast err")
68
+ }
69
+ added := val.Added
70
+ if len(added) == 1 {
71
+ s := fmt.Sprintf("Added object: %s\n", added[0].Hash)
72
return []byte(s), nil
73
}
74
71
- s := fmt.Sprintf("Added %v objects:\n", len(v))
72
- for _, obj := range v {
75
+ s := fmt.Sprintf("Added %v objects:\n", len(added))
76
+ for _, obj := range added {
77
s += fmt.Sprintf("- %s\n", obj.Hash)
78
}
79
return []byte(s), nil