Skip to content

Commit e21f234

Browse files
committed
Eliminate emit closure, so something with errors on call to emit.
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
1 parent df9d562 commit e21f234

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

core/commands/cid.go

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

1212
cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
@@ -153,21 +153,17 @@ func (i *argumentIterator) err() error {
153153

154154
func emitCids(req *cmds.Request, resp cmds.ResponseEmitter, opts cidFormatOpts) error {
155155
itr := argumentIterator{req.Arguments, req.BodyArgs()}
156-
for {
156+
var emitErr error
157+
for emitErr == nil {
157158
cidStr, ok := itr.next()
158159
if !ok {
159160
break
160161
}
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}
168163
c, err := cid.Decode(cidStr)
169164
if err != nil {
170-
emit("", err)
165+
res.ErrorMsg = err.Error()
166+
emitErr = resp.Emit(res)
171167
continue
172168
}
173169
base := opts.newBase
@@ -177,7 +173,8 @@ func emitCids(req *cmds.Request, resp cmds.ResponseEmitter, opts cidFormatOpts)
177173
if opts.verConv != nil {
178174
c, err = opts.verConv(c)
179175
if err != nil {
180-
emit("", err)
176+
res.ErrorMsg = err.Error()
177+
emitErr = resp.Emit(res)
181178
continue
182179
}
183180
}
@@ -186,7 +183,15 @@ func emitCids(req *cmds.Request, resp cmds.ResponseEmitter, opts cidFormatOpts)
186183
// no point in continuing if there is a problem with the format string
187184
return err
188185
}
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
190195
}
191196
err := itr.err()
192197
if err != nil {

0 commit comments

Comments
 (0)