@@ -156,21 +156,17 @@ func (i *argumentIterator) err() error {
156
156
157
157
func emitCids (req * cmds.Request , resp cmds.ResponseEmitter , opts cidFormatOpts ) {
158
158
itr := argumentIterator {req .Arguments , req .BodyArgs ()}
159
- for {
159
+ var emitErr error
160
+ for emitErr != nil {
160
161
cidStr , ok := itr .next ()
161
162
if ! ok {
162
163
break
163
164
}
164
- emit := func (fmtd string , err error ) {
165
- res := & CidFormatRes {CidStr : cidStr , Formatted : fmtd }
166
- if err != nil {
167
- res .ErrorMsg = err .Error ()
168
- }
169
- resp .Emit (res )
170
- }
165
+ res := & CidFormatRes {CidStr : cidStr }
171
166
c , err := cid .Decode (cidStr )
172
167
if err != nil {
173
- emit ("" , err )
168
+ res .ErrorMsg = err .Error ()
169
+ emitErr = resp .Emit (res )
174
170
continue
175
171
}
176
172
base := opts .newBase
@@ -180,17 +176,26 @@ func emitCids(req *cmds.Request, resp cmds.ResponseEmitter, opts cidFormatOpts)
180
176
if opts .verConv != nil {
181
177
c , err = opts .verConv (c )
182
178
if err != nil {
183
- emit ("" , err )
179
+ res .ErrorMsg = err .Error ()
180
+ emitErr = resp .Emit (res )
184
181
continue
185
182
}
186
183
}
187
184
str , err := cidutil .Format (opts .fmtStr , base , c )
188
185
if _ , ok := err .(cidutil.FormatStringError ); ok {
189
186
// no point in continuing if there is a problem with the format string
190
187
resp .SetError (err , cmdkit .ErrNormal )
191
- return
192
188
}
193
- emit (str , err )
189
+ if err != nil {
190
+ res .ErrorMsg = err .Error ()
191
+ } else {
192
+ res .Formatted = str
193
+ }
194
+ emitErr = resp .Emit (res )
195
+ }
196
+ if emitErr != nil {
197
+ resp .SetError (emitErr , cmdkit .ErrFatal )
198
+ return
194
199
}
195
200
err := itr .err ()
196
201
if err != nil {
0 commit comments