Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1121 from jmank88/errs
Browse files Browse the repository at this point in the history
gps: unwrapVcsErr cleanup
  • Loading branch information
sdboyer authored Sep 5, 2017
2 parents 1963157 + ba2b802 commit a87f8cc
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions internal/gps/source_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit a87f8cc

Please sign in to comment.