Skip to content

Commit

Permalink
cmds2: handle error return codes
Browse files Browse the repository at this point in the history
  • Loading branch information
jbenet committed Nov 13, 2014
1 parent 30de23c commit 949b087
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/ipfs2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ func (i *cmdInvocation) Run() (output io.Reader, err error) {
return nil, err
}

if err := res.Error(); err != nil {
return nil, err
}

return res.Reader()
}

Expand Down
5 changes: 5 additions & 0 deletions commands/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ func (r *response) Marshal() ([]byte, error) {
}
encType := EncodingType(strings.ToLower(enc))

// Special case: if text encoding and an error, just print it out.
if encType == Text && r.Error() != nil {
return []byte(r.Error().Error()), nil
}

var marshaller Marshaller
if r.req.Command() != nil && r.req.Command().Marshallers != nil {
marshaller = r.req.Command().Marshallers[encType]
Expand Down

0 comments on commit 949b087

Please sign in to comment.