From ba2b8021406c89eddd764cc83f1ef3c2e3cd2270 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Mon, 4 Sep 2017 15:08:36 -0500 Subject: [PATCH] gps: unwrapVcsErr cleanup --- internal/gps/source_errors.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/internal/gps/source_errors.go b/internal/gps/source_errors.go index bf6cf6ee..f34347a1 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 }