fixing layout to make Andy happy

This commit is contained in:
Dave Cheney 2015-12-27 16:12:56 +01:00
parent 9c1c579e61
commit 105e86fc3b
2 changed files with 15 additions and 12 deletions

View File

@ -1,15 +1,16 @@
// Package errors implements functions to manipulate errors. // Package errors implements functions to manipulate errors.
package errors package errors
type errorString string import "fmt"
func (e errorString) Error() string {
return string(e)
}
// New returns an error that formats as the given text. // New returns an error that formats as the given text.
func New(text string) error { 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. // Cause returns the underlying cause of the error, if possible.
@ -26,9 +27,10 @@ func Cause(err error) error {
if err == nil { if err == nil {
return nil return nil
} }
if err, ok := err.(interface { type causer interface {
Cause() error Cause() error
}); ok { }
if err, ok := err.(causer); ok {
return err.Cause() return err.Cause()
} }
return err return err

View File

@ -1,6 +1,7 @@
package errors package errors
import ( import (
"fmt"
"io" "io"
"reflect" "reflect"
"testing" "testing"
@ -8,7 +9,7 @@ import (
func TestNew(t *testing.T) { func TestNew(t *testing.T) {
got := New("test error") got := New("test error")
want := errorString("test error") want := fmt.Errorf("test error")
if !reflect.DeepEqual(got, want) { if !reflect.DeepEqual(got, want) {
t.Errorf("New: got %#v, want %#v", got, want) t.Errorf("New: got %#v, want %#v", got, want)
@ -20,8 +21,8 @@ func TestNewError(t *testing.T) {
err string err string
want error want error
}{ }{
{"", errorString("")}, {"", fmt.Errorf("")},
{"foo", errorString("foo")}, {"foo", fmt.Errorf("foo")},
{"foo", New("foo")}, {"foo", New("foo")},
} }
@ -42,7 +43,7 @@ type causeError struct {
} }
func (e *causeError) Error() string { return "cause error" } 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) { func TestCause(t *testing.T) {
tests := []struct { tests := []struct {