more nuanced error typing

This commit is contained in:
vilmibm 2020-03-27 11:35:39 -05:00
parent ca99096ca8
commit eb403a3b1e
2 changed files with 8 additions and 5 deletions

View file

@ -29,10 +29,12 @@ func CurrentBranch() (string, error) {
return firstLine(output), nil
}
ce := err.(*run.CmdError)
if ce.Stderr.Len() == 0 {
// Detached head
return "", errors.New("git: not on any branch")
var cmdErr *run.CmdError
if errors.As(err, &cmdErr) {
if cmdErr.Stderr.Len() == 0 {
// Detached head
return "", errors.New("git: not on any branch")
}
}
// Unknown error

View file

@ -14,7 +14,7 @@ import (
// OutputStub implements a simple utils.Runnable
type OutputStub struct {
Out []byte
Error *run.CmdError
Error error
}
func (s OutputStub) Output() ([]byte, error) {
@ -49,6 +49,7 @@ func (cs *CmdStubber) Stub(desiredOutput string) {
}
func (cs *CmdStubber) StubError(errText string) {
// TODO support error types beyond CmdError
stderrBuff := bytes.NewBufferString(errText)
args := []string{"stub"} // TODO make more real?
err := errors.New(errText)