Skip to content

Commit 13321a6

Browse files
committed
Remove dependency on xerrors
1 parent 645e200 commit 13321a6

4 files changed

Lines changed: 9 additions & 14 deletions

File tree

code.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package exitcode
22

33
import (
4+
"errors"
45
"flag"
56
"os"
6-
7-
"golang.org/x/xerrors"
87
)
98

109
// Coder is an interface to control what value Get returns.
@@ -24,11 +23,11 @@ func Get(err error) int {
2423
return 0
2524
}
2625

27-
if coder := Coder(nil); xerrors.As(err, &coder) {
26+
if coder := Coder(nil); errors.As(err, &coder) {
2827
return coder.ExitCode()
2928
}
3029

31-
if xerrors.Is(err, flag.ErrHelp) {
30+
if errors.Is(err, flag.ErrHelp) {
3231
return 2
3332
}
3433

code_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ package exitcode_test
33
import (
44
"errors"
55
"flag"
6+
"fmt"
67
"testing"
78

89
"github.com/carlmjohnson/exitcode"
9-
"golang.org/x/xerrors"
1010
)
1111

1212
func TestGet(t *testing.T) {
1313
base := exitcode.Set(errors.New(""), 4)
14-
wrapped := xerrors.Errorf("wrapping: %w", base)
14+
wrapped := fmt.Errorf("wrapping: %w", base)
1515

1616
testCases := map[string]struct {
1717
error
@@ -38,7 +38,7 @@ func TestGet(t *testing.T) {
3838

3939
func TestSet(t *testing.T) {
4040
t.Run("same-message", func(t *testing.T) {
41-
err := xerrors.New("hello")
41+
err := errors.New("hello")
4242
coder := exitcode.Set(err, 2)
4343
got := err.Error()
4444
want := coder.Error()
@@ -47,10 +47,10 @@ func TestSet(t *testing.T) {
4747
}
4848
})
4949
t.Run("keep-chain", func(t *testing.T) {
50-
err := xerrors.New("hello")
50+
err := errors.New("hello")
5151
coder := exitcode.Set(err, 3)
5252

53-
if !xerrors.Is(coder, err) {
53+
if !errors.Is(coder, err) {
5454
t.Errorf("broken chain: %v is not %v", coder, err)
5555
}
5656
})

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module github.com/carlmjohnson/exitcode
22

3-
go 1.12
4-
5-
require golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898
3+
go 1.13

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
2-
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

0 commit comments

Comments
 (0)