more nuanced error typing
This commit is contained in:
parent
ca99096ca8
commit
eb403a3b1e
2 changed files with 8 additions and 5 deletions
10
git/git.go
10
git/git.go
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue