From ca2828f33c457fa105e890f8738049d92893bfae Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Thu, 13 Nov 2014 02:34:04 -0800 Subject: [PATCH] feat(commands) add ClientError(msg) helper and use it to return a fancy error to the client in the tour @jbenet this exists now License: MIT Signed-off-by: Brian Tiger Chow --- cmd/ipfs2/tour.go | 2 +- commands/command.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/ipfs2/tour.go b/cmd/ipfs2/tour.go index bbc1ed1c1..da0d6f422 100644 --- a/cmd/ipfs2/tour.go +++ b/cmd/ipfs2/tour.go @@ -53,7 +53,7 @@ IPFS very quickly. To start, run: t, err := tourGet(id) if err != nil { - return nil, err + return nil, cmds.ClientError(err.Error()) } err = tourShow(out, t) diff --git a/commands/command.go b/commands/command.go index 0301e9d1b..5e031338e 100644 --- a/commands/command.go +++ b/commands/command.go @@ -65,9 +65,9 @@ type Command struct { } // ErrNotCallable signals a command that cannot be called. -var ErrNotCallable = errors.New("This command can't be called directly. Try one of its subcommands.") +var ErrNotCallable = ClientError("This command can't be called directly. Try one of its subcommands.") -var ErrNoFormatter = errors.New("This command cannot be formatted to plain text") +var ErrNoFormatter = ClientError("This command cannot be formatted to plain text") var ErrIncorrectType = errors.New("The command returned a value with a different type than expected") @@ -276,3 +276,7 @@ func checkArgValue(v interface{}, def Argument) error { return nil } + +func ClientError(msg string) error { + return &Error{Code: ErrClient, Message: msg} +}