Skip to content

Commit df9d562

Browse files
committed
Address code review.
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
1 parent 844ce60 commit df9d562

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

core/commands/cid.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"sort"
77
"strings"
88
"unicode"
9+
10+
"github.com/ipfs/go-ipfs/core/commands/e"
911

1012
cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
1113
cmds "gx/ipfs/QmPXR4tNdLbp8HsZiPMjpsgqphX9Vhw2J6Jh5MKH2ovW3D/go-ipfs-cmds"
@@ -66,7 +68,7 @@ The optional format string is a printf style format string:
6668
case "1":
6769
opts.verConv = toCidV1
6870
default:
69-
return fmt.Errorf("invalid cid version: %s\n", verStr)
71+
return fmt.Errorf("invalid cid version: %s", verStr)
7072
}
7173

7274
if baseStr != "" {
@@ -82,7 +84,7 @@ The optional format string is a printf style format string:
8284
return emitCids(req, resp, opts)
8385
},
8486
PostRun: cmds.PostRunMap{
85-
cmds.CLI: streamRes(func(v interface{}, out io.Writer) nonFatalError {
87+
cmds.CLI: streamResults(func(v interface{}, out io.Writer) nonFatalError {
8688
r := v.(*CidFormatRes)
8789
if r.ErrorMsg != "" {
8890
return nonFatalError(fmt.Sprintf("%s: %s", r.CidStr, r.ErrorMsg))
@@ -230,7 +232,10 @@ var basesCmd = &cmds.Command{
230232
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, val0 interface{}) error {
231233
prefixes, _ := req.Options["prefix"].(bool)
232234
numeric, _ := req.Options["numeric"].(bool)
233-
val := val0.([]CodeAndName)
235+
val, ok := val0.([]CodeAndName)
236+
if !ok {
237+
return e.TypeErr(val, val0)
238+
}
234239
sort.Sort(multibaseSorter{val})
235240
for _, v := range val {
236241
code := v.Code
@@ -274,7 +279,10 @@ var codecsCmd = &cmds.Command{
274279
Encoders: cmds.EncoderMap{
275280
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, val0 interface{}) error {
276281
numeric, _ := req.Options["numeric"].(bool)
277-
val := val0.([]CodeAndName)
282+
val, ok := val0.([]CodeAndName)
283+
if !ok {
284+
return e.TypeErr(val, val0)
285+
}
278286
sort.Sort(codeAndNameSorter{val})
279287
for _, v := range val {
280288
if numeric {

core/commands/commands.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ func unwrapOutput(i interface{}) (interface{}, error) {
153153

154154
type nonFatalError string
155155

156-
// streamRes is a helper function to stream results, that possibly
157-
// contain with non-fatal, the helper function is allowed to panic on
158-
// internal errors
159-
func streamRes(procVal func(interface{}, io.Writer) nonFatalError) func(cmds.Response, cmds.ResponseEmitter) error {
156+
// streamResults is a helper function to stream results that possibly
157+
// contain non-fatal errors. The helper function is allowed to panic
158+
// on internal errors.
159+
func streamResults(procVal func(interface{}, io.Writer) nonFatalError) func(cmds.Response, cmds.ResponseEmitter) error {
160160
return func(res cmds.Response, re cmds.ResponseEmitter) (err error) {
161161
defer func() {
162162
if r := recover(); r != nil {

core/commands/filestore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ The output is:
7272
return res.Emit(out)
7373
},
7474
PostRun: cmds.PostRunMap{
75-
cmds.CLI: streamRes(func(v interface{}, out io.Writer) nonFatalError {
75+
cmds.CLI: streamResults(func(v interface{}, out io.Writer) nonFatalError {
7676
r := v.(*filestore.ListRes)
7777
if r.ErrorMsg != "" {
7878
return nonFatalError(r.ErrorMsg)

0 commit comments

Comments
 (0)