Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some significance to where Wrap is called from, so that wrapping somewhere other than where the error occurred is a bit strange, but I think that Masterminds/vcs would have to incorporate the errors package in order to avoid this, so it's likely nbd.

default:
return err
}
Expand Down