aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/gopkg.in/urfave/cli.v1/errors.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gopkg.in/urfave/cli.v1/errors.go')
-rw-r--r--vendor/gopkg.in/urfave/cli.v1/errors.go28
1 files changed, 23 insertions, 5 deletions
diff --git a/vendor/gopkg.in/urfave/cli.v1/errors.go b/vendor/gopkg.in/urfave/cli.v1/errors.go
index ea551be16..0206ff491 100644
--- a/vendor/gopkg.in/urfave/cli.v1/errors.go
+++ b/vendor/gopkg.in/urfave/cli.v1/errors.go
@@ -24,7 +24,7 @@ func NewMultiError(err ...error) MultiError {
return MultiError{Errors: err}
}
-// Error implents the error interface.
+// Error implements the error interface.
func (m MultiError) Error() string {
errs := make([]string, len(m.Errors))
for i, err := range m.Errors {
@@ -34,6 +34,10 @@ func (m MultiError) Error() string {
return strings.Join(errs, "\n")
}
+type ErrorFormatter interface {
+ Format(s fmt.State, verb rune)
+}
+
// ExitCoder is the interface checked by `App` and `Command` for a custom exit
// code
type ExitCoder interface {
@@ -44,11 +48,11 @@ type ExitCoder interface {
// ExitError fulfills both the builtin `error` interface and `ExitCoder`
type ExitError struct {
exitCode int
- message string
+ message interface{}
}
// NewExitError makes a new *ExitError
-func NewExitError(message string, exitCode int) *ExitError {
+func NewExitError(message interface{}, exitCode int) *ExitError {
return &ExitError{
exitCode: exitCode,
message: message,
@@ -58,7 +62,7 @@ func NewExitError(message string, exitCode int) *ExitError {
// Error returns the string message, fulfilling the interface required by
// `error`
func (ee *ExitError) Error() string {
- return ee.message
+ return fmt.Sprintf("%v", ee.message)
}
// ExitCode returns the exit code, fulfilling the interface required by
@@ -78,7 +82,11 @@ func HandleExitCoder(err error) {
if exitErr, ok := err.(ExitCoder); ok {
if err.Error() != "" {
- fmt.Fprintln(ErrWriter, err)
+ if _, ok := exitErr.(ErrorFormatter); ok {
+ fmt.Fprintf(ErrWriter, "%+v\n", err)
+ } else {
+ fmt.Fprintln(ErrWriter, err)
+ }
}
OsExiter(exitErr.ExitCode())
return
@@ -88,5 +96,15 @@ func HandleExitCoder(err error) {
for _, merr := range multiErr.Errors {
HandleExitCoder(merr)
}
+ return
+ }
+
+ if err.Error() != "" {
+ if _, ok := err.(ErrorFormatter); ok {
+ fmt.Fprintf(ErrWriter, "%+v\n", err)
+ } else {
+ fmt.Fprintln(ErrWriter, err)
+ }
}
+ OsExiter(1)
}