X Tutup
Skip to content

Commit eb403a3

Browse files
committed
more nuanced error typing
1 parent ca99096 commit eb403a3

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

git/git.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ func CurrentBranch() (string, error) {
2929
return firstLine(output), nil
3030
}
3131

32-
ce := err.(*run.CmdError)
33-
if ce.Stderr.Len() == 0 {
34-
// Detached head
35-
return "", errors.New("git: not on any branch")
32+
var cmdErr *run.CmdError
33+
if errors.As(err, &cmdErr) {
34+
if cmdErr.Stderr.Len() == 0 {
35+
// Detached head
36+
return "", errors.New("git: not on any branch")
37+
}
3638
}
3739

3840
// Unknown error

test/helpers.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
// OutputStub implements a simple utils.Runnable
1515
type OutputStub struct {
1616
Out []byte
17-
Error *run.CmdError
17+
Error error
1818
}
1919

2020
func (s OutputStub) Output() ([]byte, error) {
@@ -49,6 +49,7 @@ func (cs *CmdStubber) Stub(desiredOutput string) {
4949
}
5050

5151
func (cs *CmdStubber) StubError(errText string) {
52+
// TODO support error types beyond CmdError
5253
stderrBuff := bytes.NewBufferString(errText)
5354
args := []string{"stub"} // TODO make more real?
5455
err := errors.New(errText)

0 commit comments

Comments
 (0)
X Tutup