fixing layout to make Andy happy
diff --git a/errors.go b/errors.go
index 1c3c713..18a9e68 100644
--- a/errors.go
+++ b/errors.go
@@ -1,15 +1,16 @@
// Package errors implements functions to manipulate errors.
package errors
-type errorString string
-
-func (e errorString) Error() string {
- return string(e)
-}
+import "fmt"
// New returns an error that formats as the given text.
func New(text string) error {
- return errorString(text)
+ return Errorf(text)
+}
+
+// Errorf returns a formatted error.
+func Errorf(format string, args ...interface{}) error {
+ return fmt.Errorf(format, args...)
}
// Cause returns the underlying cause of the error, if possible.
@@ -26,9 +27,10 @@
if err == nil {
return nil
}
- if err, ok := err.(interface {
+ type causer interface {
Cause() error
- }); ok {
+ }
+ if err, ok := err.(causer); ok {
return err.Cause()
}
return err
diff --git a/errors_test.go b/errors_test.go
index e024b5d..7c094c4 100644
--- a/errors_test.go
+++ b/errors_test.go
@@ -1,6 +1,7 @@
package errors
import (
+ "fmt"
"io"
"reflect"
"testing"
@@ -8,7 +9,7 @@
func TestNew(t *testing.T) {
got := New("test error")
- want := errorString("test error")
+ want := fmt.Errorf("test error")
if !reflect.DeepEqual(got, want) {
t.Errorf("New: got %#v, want %#v", got, want)
@@ -20,8 +21,8 @@
err string
want error
}{
- {"", errorString("")},
- {"foo", errorString("foo")},
+ {"", fmt.Errorf("")},
+ {"foo", fmt.Errorf("foo")},
{"foo", New("foo")},
}
@@ -42,7 +43,7 @@
}
func (e *causeError) Error() string { return "cause error" }
-func (e *causeError) Cause() error { return e.cause }
+func (e *causeError) Cause() error { return e.cause }
func TestCause(t *testing.T) {
tests := []struct {