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

Commit a87f8cc

Browse files
authored
Merge pull request #1121 from jmank88/errs
gps: unwrapVcsErr cleanup
2 parents 1963157 + ba2b802 commit a87f8cc

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

internal/gps/source_errors.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@
55
package gps
66

77
import (
8-
"fmt"
9-
108
"github.com/Masterminds/vcs"
9+
"github.com/pkg/errors"
1110
)
1211

13-
// unwrapVcsErr will extract actual command output from a vcs err, if possible
14-
//
15-
// TODO this is really dumb, lossy, and needs proper handling
12+
// unwrapVcsErr recognizes *vcs.LocalError and *vsc.RemoteError, and returns a form
13+
// preserving the actual vcs command output and error, in addition to the message.
14+
// All other types pass through unchanged.
1615
func unwrapVcsErr(err error) error {
17-
switch verr := err.(type) {
16+
switch t := err.(type) {
1817
case *vcs.LocalError:
19-
return fmt.Errorf("%s: %s", verr.Error(), verr.Out())
18+
cause, out, msg := t.Original(), t.Out(), t.Error()
19+
return errors.Wrap(errors.Wrap(cause, out), msg)
2020
case *vcs.RemoteError:
21-
return fmt.Errorf("%s: %s", verr.Error(), verr.Out())
21+
cause, out, msg := t.Original(), t.Out(), t.Error()
22+
return errors.Wrap(errors.Wrap(cause, out), msg)
2223
default:
2324
return err
2425
}

0 commit comments

Comments
 (0)