Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print a nicer error on timeout/cancel #137

Merged
merged 1 commit into from
Dec 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need a cmdkit.Error, we just need the error message.


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