From a3a4e5b78eeb52b3b290a98e6f00ce809911b0fb Mon Sep 17 00:00:00 2001 From: risk danger olson Date: Thu, 18 Aug 2016 15:43:28 -0600 Subject: [PATCH] errors: remove GetInnerError() and ErrorWithStack --- commands/commands.go | 56 ++++++++++++++++---------------------------- errors/errors.go | 4 ---- lfs/attribute.go | 2 +- 3 files changed, 21 insertions(+), 41 deletions(-) diff --git a/commands/commands.go b/commands/commands.go index 75f1762c..71ce9974 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -85,18 +85,21 @@ func TransferManifest() *transfer.Manifest { // Error prints a formatted message to Stderr. It also gets printed to the // panic log if one is created for this command. func Error(format string, args ...interface{}) { - line := format - if len(args) > 0 { - line = fmt.Sprintf(format, args...) + if len(args) == 0 { + fmt.Fprintln(ErrorWriter, format) + return } - fmt.Fprintln(ErrorWriter, line) + fmt.Fprintf(ErrorWriter, format+"\n", args...) } // Print prints a formatted message to Stdout. It also gets printed to the // panic log if one is created for this command. func Print(format string, args ...interface{}) { - line := fmt.Sprintf(format, args...) - fmt.Fprintln(OutputWriter, line) + if len(args) == 0 { + fmt.Fprintln(OutputWriter, format) + return + } + fmt.Fprintf(OutputWriter, format+"\n", args...) } // Exit prints a formatted message and exits. @@ -118,21 +121,12 @@ func FullError(err error) { } func errorWith(err error, fatalErrFn func(error, string, ...interface{}), errFn func(string, ...interface{})) { - var innermsg string - if inner := errors.GetInnerError(err); inner != nil { - innermsg = inner.Error() - } - - errmsg := err.Error() - if errmsg != innermsg { - Error(innermsg) - } - if Debugging || errors.IsFatalError(err) { - fatalErrFn(err, errmsg) - } else { - errFn(errmsg) + fatalErrFn(err, "") + return } + + errFn("%s", err) } // Debug prints a formatted message if debugging is enabled. The formatted @@ -147,7 +141,9 @@ func Debug(format string, args ...interface{}) { // LoggedError prints a formatted message to Stderr and writes a stack trace for // the error to a log file without exiting. func LoggedError(err error, format string, args ...interface{}) { - Error(format, args...) + if len(format) > 0 { + Error(format, args...) + } file := handlePanic(err) if len(file) > 0 { @@ -260,17 +256,11 @@ func logPanicToWriter(w io.Writer, loggedError error) { w.Write(ErrorBuffer.Bytes()) fmt.Fprintln(w) - fmt.Fprintln(w, loggedError.Error()) - - if err, ok := loggedError.(ErrorWithStack); ok { - fmt.Fprintln(w, err.InnerError()) - for key, value := range err.Context() { - fmt.Fprintf(w, "%s=%s\n", key, value) - } - w.Write(err.Stack()) - } else { - w.Write(errors.Stack()) + fmt.Fprintf(w, "%+v\n", loggedError) + for key, val := range errors.ErrorContext(err) { + fmt.Fprintf(w, "%s=%v\n", key, val) } + fmt.Fprintln(w, "\nENV:") // log the environment @@ -279,12 +269,6 @@ func logPanicToWriter(w io.Writer, loggedError error) { } } -type ErrorWithStack interface { - Context() map[string]string - InnerError() string - Stack() []byte -} - func determineIncludeExcludePaths(config *config.Configuration, includeArg, excludeArg *string) (include, exclude []string) { if includeArg == nil { include = config.FetchIncludePaths() diff --git a/errors/errors.go b/errors/errors.go index 4ded1e37..07c7f015 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -232,10 +232,6 @@ func IsRetriableError(err error) bool { return false } -func GetInnerError(err error) error { - return parentOf(err) -} - // ErrorSetContext sets a value in the error's context. If the error has not // been wrapped, it does nothing. func ErrorSetContext(err error, key string, value interface{}) { diff --git a/lfs/attribute.go b/lfs/attribute.go index cef8d946..e8c99655 100644 --- a/lfs/attribute.go +++ b/lfs/attribute.go @@ -90,7 +90,7 @@ func (a *Attribute) set(key, value string, opt InstallOptions) error { } return err } else if currentValue != value { - return fmt.Errorf("The %s attribute should be \"%s\" but is \"%s\"", + return fmt.Errorf("The %s attribute should be %q but is %q", key, value, currentValue) }