diff --git a/internal/gps/source_errors.go b/internal/gps/source_errors.go index bf6cf6ee69..f34347a1fa 100644 --- a/internal/gps/source_errors.go +++ b/internal/gps/source_errors.go @@ -5,20 +5,21 @@ package gps import ( - "fmt" - "github.com/Masterminds/vcs" + "github.com/pkg/errors" ) -// unwrapVcsErr will extract actual command output from a vcs err, if possible -// -// TODO this is really dumb, lossy, and needs proper handling +// unwrapVcsErr recognizes *vcs.LocalError and *vsc.RemoteError, and returns a form +// preserving the actual vcs command output and error, in addition to the message. +// All other types pass through unchanged. func unwrapVcsErr(err error) error { - switch verr := err.(type) { + switch t := err.(type) { case *vcs.LocalError: - return fmt.Errorf("%s: %s", verr.Error(), verr.Out()) + cause, out, msg := t.Original(), t.Out(), t.Error() + return errors.Wrap(errors.Wrap(cause, out), msg) case *vcs.RemoteError: - return fmt.Errorf("%s: %s", verr.Error(), verr.Out()) + cause, out, msg := t.Original(), t.Out(), t.Error() + return errors.Wrap(errors.Wrap(cause, out), msg) default: return err }