Skip to content

Commit 281f67c

Browse files
committed
Remove drop in replacement for standard library errors package
1 parent df5956e commit 281f67c

14 files changed

+67
-171
lines changed

README

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
What?
22

3-
Package errors provides things for working with single and multiple errors and
4-
errors from deferred function calls.
3+
Package errutil provides things for working with multiple errors and errors
4+
from deferred function calls.
55

66
Import
77

8-
import "sethwklein.net/go/errors"
8+
import "sethwklein.net/go/errutil"
99

1010
Documentation
1111

12-
http://godoc.org/sethwklein.net/go/errors
12+
http://godoc.org/sethwklein.net/go/errutil

benchmark_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package errors_test
1+
package errutil_test
22

33
import (
44
"fmt"
5-
"sethwklein.net/go/errors"
5+
"sethwklein.net/go/errutil"
66
"testing"
77
)
88

@@ -17,13 +17,13 @@ func BenchmarkBase(b *testing.B) {
1717
func BenchmarkAppend(b *testing.B) {
1818
var list error
1919
for i := 0; i < b.N; i++ {
20-
list = errors.Append(list, fmt.Errorf("number %v", i))
20+
list = errutil.Append(list, fmt.Errorf("number %v", i))
2121
}
2222
}
2323

2424
func BenchmarkNil(b *testing.B) {
2525
var list error
2626
for i := 0; i < b.N; i++ {
27-
list = errors.Append(list, nil)
27+
list = errutil.Append(list, nil)
2828
}
2929
}

benchmark_walkn_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package errors_test
1+
package errutil_test
22

33
import (
44
"fmt"
5-
"sethwklein.net/go/errors"
5+
"sethwklein.net/go/errutil"
66
"testing"
77
)
88

@@ -12,7 +12,7 @@ const attentionSpan = 30
1212
func BenchmarkWalkPanic(b *testing.B) {
1313
var list error
1414
for i := 1; i <= listLen; i++ {
15-
list = errors.Append(list, fmt.Errorf("number %v", i))
15+
list = errutil.Append(list, fmt.Errorf("number %v", i))
1616
}
1717
b.ResetTimer()
1818
for i := 0; i < b.N; i++ {
@@ -24,7 +24,7 @@ func BenchmarkWalkPanic(b *testing.B) {
2424
}()
2525
n := attentionSpan
2626
i := 0
27-
errors.Walk(list, func(e error) {
27+
errutil.Walk(list, func(e error) {
2828
_ = e
2929
i++
3030
if i >= n {
@@ -38,13 +38,13 @@ func BenchmarkWalkPanic(b *testing.B) {
3838
func BenchmarkWalkIgnore(b *testing.B) {
3939
var list error
4040
for i := 1; i <= listLen; i++ {
41-
list = errors.Append(list, fmt.Errorf("number %v", i))
41+
list = errutil.Append(list, fmt.Errorf("number %v", i))
4242
}
4343
b.ResetTimer()
4444
for i := 0; i < b.N; i++ {
4545
n := attentionSpan
4646
i := 0
47-
errors.Walk(list, func(e error) {
47+
errutil.Walk(list, func(e error) {
4848
i++
4949
if i > n {
5050
return
@@ -57,11 +57,11 @@ func BenchmarkWalkIgnore(b *testing.B) {
5757
func BenchmarkWalkN(b *testing.B) {
5858
var list error
5959
for i := 1; i <= listLen; i++ {
60-
list = errors.Append(list, fmt.Errorf("number %v", i))
60+
list = errutil.Append(list, fmt.Errorf("number %v", i))
6161
}
6262
b.ResetTimer()
6363
for i := 0; i < b.N; i++ {
64-
errors.WalkN(list, attentionSpan, func(e error) {
64+
errutil.WalkN(list, attentionSpan, func(e error) {
6565
_ = e
6666
})
6767
}

call_test.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
package errors
1+
package errutil
22

33
import (
4+
"errors"
45
"io"
56
"reflect"
67
"testing"
78
)
89

910
func TestCall(t *testing.T) {
1011
var err error
11-
e := New("appended error")
12+
e := errors.New("appended error")
1213
AppendCall(&err, func() error {
1314
return e
1415
})
@@ -55,24 +56,24 @@ func TestCallNilNil(t *testing.T) {
5556
}
5657

5758
func TestCallErrNil(t *testing.T) {
58-
w := New("write error")
59+
w := errors.New("write error")
5960
err := doCall(w, nil)
6061
if err != w {
6162
t.Errorf("%v != %v", err, w)
6263
}
6364
}
6465

6566
func TestCallNilErr(t *testing.T) {
66-
c := New("close error")
67+
c := errors.New("close error")
6768
err := doCall(nil, c)
6869
if err != c {
6970
t.Errorf("%v != %v", err, c)
7071
}
7172
}
7273

7374
func TestCallErrErr(t *testing.T) {
74-
w := New("write error")
75-
c := New("close error")
75+
w := errors.New("write error")
76+
c := errors.New("close error")
7677
err := doCall(w, c)
7778
correct := &errorList{[]error{w, c}}
7879
if !reflect.DeepEqual(err, correct) {

doc.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Package errors provides things for working with single and multiple errors.
2-
//
3-
// It is a drop in replacement for the standard errors package
4-
// but with extra features for handling multiple errors
5-
// and correctly handling errors from deferred calls.
6-
package errors
1+
// Package errutil provides things for working with multiple errors and
2+
// correctly handling errors from deferred calls.
3+
package errutil

errorlist.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package errors
1+
package errutil
22

33
import "strings"
44

@@ -34,6 +34,7 @@ type Firster interface {
3434
First() error
3535
}
3636

37+
// First implements ErrorList.First.
3738
func (list *errorList) First() error {
3839
// They're not supposed to do this, but let's be permissive.
3940
if len(list.a) < 1 {

errorlists_test.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
// Copyright 2011 The Go Authors. All rights reserved.
2+
// Copyright 2013 Seth W. Klein. All rights reserved.
23
// Use of this source code is governed by a BSD-style
34
// license that can be found in the LICENSE file.
4-
// Portions copyright 2013 Seth W. Klein.
55

6-
package errors_test
6+
package errutil_test
77

88
import (
9-
"sethwklein.net/go/errors"
9+
"errors"
10+
"sethwklein.net/go/errutil"
1011
"testing"
1112
)
1213

1314
func TestNewEqualList(t *testing.T) {
1415
// Different allocations should not be equal.
15-
if errors.Append(errors.New("ab"), errors.New("cd")) == errors.Append(errors.New("ab"), errors.New("cd")) {
16+
if errutil.Append(errors.New("ab"), errors.New("cd")) == errutil.Append(errors.New("ab"), errors.New("cd")) {
1617
t.Errorf(`Append(New("ab"), New("cd")) == Append(New("ab"), New("cd"))`)
1718
}
1819

1920
// Same allocation should be equal to itself (not crash).
20-
err := errors.Append(errors.New("jk"), errors.New("lm"))
21+
err := errutil.Append(errors.New("jk"), errors.New("lm"))
2122
if err != err {
2223
t.Errorf(`err != err`)
2324
}
2425
}
2526

2627
func TestErrorMethodList(t *testing.T) {
27-
err := errors.Append(errors.New("ab"), errors.New("cd"))
28+
err := errutil.Append(errors.New("ab"), errors.New("cd"))
2829
if err.Error() != "ab"+"\n"+"cd" {
2930
t.Errorf(`Append(New("ab"), New("cd")) = %q, want %q`,
3031
err.Error(), "ab\ncd")

errors.go

-19
This file was deleted.

errors_test.go

-53
This file was deleted.

example_test.go

-34
This file was deleted.

examplelist_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
package errors_test
1+
package errutil_test
22

33
import (
44
"fmt"
55
"io/ioutil"
66
"os"
77
"path/filepath"
8-
"sethwklein.net/go/errors"
8+
"sethwklein.net/go/errutil"
99
)
1010

1111
func ReinventTheIOUtil(filename string) (buf []byte, err error) {
1212
f, err := os.Open(filename)
1313
if err != nil {
1414
return nil, err
1515
}
16-
defer errors.AppendCall(&err, f.Close)
16+
defer errutil.AppendCall(&err, f.Close)
1717

1818
buf, err = ioutil.ReadAll(f)
1919
if err != nil {
@@ -26,7 +26,7 @@ func ExampleAppendCall() {
2626
buf, err := ReinventTheIOUtil("errorlist.go")
2727
if err != nil {
2828
command := filepath.Base(os.Args[0])
29-
errors.Walk(err, func(e error) {
29+
errutil.Walk(err, func(e error) {
3030
fmt.Fprintf(os.Stderr, "%s, Error: %s\n", command, e)
3131
})
3232
}

0 commit comments

Comments
 (0)