@cryptotaxi247 / kubo / commits / 7edc7de28

Eliminate `emit` closure, so something with errors on call to emit.

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

Kevin Atkinson committed Aug 30, 2018 at 03:19 UTC 7edc7de28822b6ea0fe237e2d1ad6e230919d3f8
1 file changed +17 -12
core/commands/cid.go
+17 -12
@@ -6,7 +6,7 @@ import (
6 "sort"
7 "strings"
8 "unicode"
9 -
9 +
10 "github.com/ipfs/go-ipfs/core/commands/e"
11
12 cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
@@ -153,21 +153,17 @@ func (i *argumentIterator) err() error {
153
154 func emitCids(req *cmds.Request, resp cmds.ResponseEmitter, opts cidFormatOpts) error {
155 itr := argumentIterator{req.Arguments, req.BodyArgs()}
156 - for {
156 + var emitErr error
157 + for emitErr == nil {
158 cidStr, ok := itr.next()
159 if !ok {
160 break
161 }
161 - emit := func(fmtd string, err error) {
162 - res := &CidFormatRes{CidStr: cidStr, Formatted: fmtd}
163 - if err != nil {
164 - res.ErrorMsg = err.Error()
165 - }
166 - resp.Emit(res)
167 - }
162 + res := &CidFormatRes{CidStr: cidStr}
163 c, err := cid.Decode(cidStr)
164 if err != nil {
170 - emit("", err)
165 + res.ErrorMsg = err.Error()
166 + emitErr = resp.Emit(res)
167 continue
168 }
169 base := opts.newBase
@@ -177,7 +173,8 @@ func emitCids(req *cmds.Request, resp cmds.ResponseEmitter, opts cidFormatOpts)
173 if opts.verConv != nil {
174 c, err = opts.verConv(c)
175 if err != nil {
180 - emit("", err)
176 + res.ErrorMsg = err.Error()
177 + emitErr = resp.Emit(res)
178 continue
179 }
180 }
@@ -186,7 +183,15 @@ func emitCids(req *cmds.Request, resp cmds.ResponseEmitter, opts cidFormatOpts)
183 // no point in continuing if there is a problem with the format string
184 return err
185 }
189 - emit(str, err)
186 + if err != nil {
187 + res.ErrorMsg = err.Error()
188 + } else {
189 + res.Formatted = str
190 + }
191 + emitErr = resp.Emit(res)
192 + }
193 + if emitErr != nil {
194 + return emitErr
195 }
196 err := itr.err()
197 if err != nil {