Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Commit 105e86f

Browse files
committed
fixing layout to make Andy happy
1 parent 9c1c579 commit 105e86f

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

errors.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
// Package errors implements functions to manipulate errors.
22
package errors
33

4-
type errorString string
5-
6-
func (e errorString) Error() string {
7-
return string(e)
8-
}
4+
import "fmt"
95

106
// New returns an error that formats as the given text.
117
func New(text string) error {
12-
return errorString(text)
8+
return Errorf(text)
9+
}
10+
11+
// Errorf returns a formatted error.
12+
func Errorf(format string, args ...interface{}) error {
13+
return fmt.Errorf(format, args...)
1314
}
1415

1516
// Cause returns the underlying cause of the error, if possible.
@@ -26,9 +27,10 @@ func Cause(err error) error {
2627
if err == nil {
2728
return nil
2829
}
29-
if err, ok := err.(interface {
30+
type causer interface {
3031
Cause() error
31-
}); ok {
32+
}
33+
if err, ok := err.(causer); ok {
3234
return err.Cause()
3335
}
3436
return err

errors_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package errors
22

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

910
func TestNew(t *testing.T) {
1011
got := New("test error")
11-
want := errorString("test error")
12+
want := fmt.Errorf("test error")
1213

1314
if !reflect.DeepEqual(got, want) {
1415
t.Errorf("New: got %#v, want %#v", got, want)
@@ -20,8 +21,8 @@ func TestNewError(t *testing.T) {
2021
err string
2122
want error
2223
}{
23-
{"", errorString("")},
24-
{"foo", errorString("foo")},
24+
{"", fmt.Errorf("")},
25+
{"foo", fmt.Errorf("foo")},
2526
{"foo", New("foo")},
2627
}
2728

@@ -42,7 +43,7 @@ type causeError struct {
4243
}
4344

4445
func (e *causeError) Error() string { return "cause error" }
45-
func (e *causeError) Cause() error { return e.cause }
46+
func (e *causeError) Cause() error { return e.cause }
4647

4748
func TestCause(t *testing.T) {
4849
tests := []struct {

0 commit comments

Comments
 (0)