Skip to content

Commit

Permalink
Merge pull request #137 from ipfs/fix/go-ipfs-3785
Browse files Browse the repository at this point in the history
print a nicer error on timeout/cancel
  • Loading branch information
Stebalien authored Dec 13, 2018
2 parents 4263ae6 + af847ec commit 18fbb38
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions cli/responseemitter.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package cli

import (
"context"
"fmt"
"io"
"os"
"sync"
"syscall"

"github.com/ipfs/go-ipfs-cmdkit"
"github.com/ipfs/go-ipfs-cmds"
"github.com/ipfs/go-ipfs-cmds/debug"
)
Expand Down Expand Up @@ -63,19 +63,16 @@ func (re *responseEmitter) SetLength(l uint64) {
}

func (re *responseEmitter) CloseWithError(err error) error {
if err == nil {
var msg string
switch err {
case nil:
return re.Close()
}

if e, ok := err.(cmdkit.Error); ok {
err = &e
}

e, ok := err.(*cmdkit.Error)
if !ok {
e = &cmdkit.Error{
Message: err.Error(),
}
case context.Canceled:
msg = "canceled"
case context.DeadlineExceeded:
msg = "timed out"
default:
msg = err.Error()
}

re.l.Lock()
Expand All @@ -87,7 +84,7 @@ func (re *responseEmitter) CloseWithError(err error) error {

re.exit = 1 // TODO we could let err carry an exit code

_, err = fmt.Fprintln(re.stderr, "Error:", e.Message)
_, err = fmt.Fprintln(re.stderr, "Error:", msg)
if err != nil {
return err
}
Expand Down

0 comments on commit 18fbb38

Please sign in to comment.