@cryptotaxi247 / kubo / commits / c0a873c27

Address code review.

License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed Aug 29, 2018 at 23:39 UTC c0a873c27fe412a1ad76e5e479aa5d6a314381da
3 files changed +17 -9
core/commands/cid.go
+12 -4
@@ -6,6 +6,8 @@ import (
6 "sort"
7 "strings"
8 "unicode"
9 +
10 + "github.com/ipfs/go-ipfs/core/commands/e"
11
12 cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
13 mhash "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
@@ -66,7 +68,7 @@ The optional format string is a printf style format string:
68 case "1":
69 opts.verConv = toCidV1
70 default:
69 - return fmt.Errorf("invalid cid version: %s\n", verStr)
71 + return fmt.Errorf("invalid cid version: %s", verStr)
72 }
73
74 if baseStr != "" {
@@ -82,7 +84,7 @@ The optional format string is a printf style format string:
84 return emitCids(req, resp, opts)
85 },
86 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 {
88 r := v.(*CidFormatRes)
89 if r.ErrorMsg != "" {
90 return nonFatalError(fmt.Sprintf("%s: %s", r.CidStr, r.ErrorMsg))
@@ -230,7 +232,10 @@ var basesCmd = &cmds.Command{
232 cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, val0 interface{}) error {
233 prefixes, _ := req.Options["prefix"].(bool)
234 numeric, _ := req.Options["numeric"].(bool)
233 - val := val0.([]CodeAndName)
235 + val, ok := val0.([]CodeAndName)
236 + if !ok {
237 + return e.TypeErr(val, val0)
238 + }
239 sort.Sort(multibaseSorter{val})
240 for _, v := range val {
241 code := v.Code
@@ -274,7 +279,10 @@ var codecsCmd = &cmds.Command{
279 Encoders: cmds.EncoderMap{
280 cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, val0 interface{}) error {
281 numeric, _ := req.Options["numeric"].(bool)
277 - val := val0.([]CodeAndName)
282 + val, ok := val0.([]CodeAndName)
283 + if !ok {
284 + return e.TypeErr(val, val0)
285 + }
286 sort.Sort(codeAndNameSorter{val})
287 for _, v := range val {
288 if numeric {
core/commands/commands.go
+4 -4
@@ -153,10 +153,10 @@ func unwrapOutput(i interface{}) (interface{}, error) {
153
154 type nonFatalError string
155
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 {
160 return func(res cmds.Response, re cmds.ResponseEmitter) (err error) {
161 defer func() {
162 if r := recover(); r != nil {
core/commands/filestore.go
+1 -1
@@ -72,7 +72,7 @@ The output is:
72 return res.Emit(out)
73 },
74 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 {
76 r := v.(*filestore.ListRes)
77 if r.ErrorMsg != "" {
78 return nonFatalError(r.ErrorMsg)