@cryptotaxi247 / kubo / commits / 7daf88890

cmds2: handle error return codes

Juan Batiz-Benet committed Nov 12, 2014 at 22:48 UTC 7daf888902b854a7144154851ad3f54243df5351
2 files changed +9
cmd/ipfs2/main.go
+4
@@ -150,6 +150,10 @@ func (i *cmdInvocation) Run() (output io.Reader, err error) {
150 return nil, err
151 }
152
153 + if err := res.Error(); err != nil {
154 + return nil, err
155 + }
156 +
157 return res.Reader()
158 }
159
commands/response.go
+5
@@ -117,6 +117,11 @@ func (r *response) Marshal() ([]byte, error) {
117 }
118 encType := EncodingType(strings.ToLower(enc))
119
120 + // Special case: if text encoding and an error, just print it out.
121 + if encType == Text && r.Error() != nil {
122 + return []byte(r.Error().Error()), nil
123 + }
124 +
125 var marshaller Marshaller
126 if r.req.Command() != nil && r.req.Command().Marshallers != nil {
127 marshaller = r.req.Command().Marshallers[encType]