mirror of
https://github.com/pkg/errors.git
synced 2025-05-31 11:42:45 +00:00
fixing layout to make Andy happy
This commit is contained in:
parent
9c1c579e61
commit
105e86fc3b
18
errors.go
18
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 @@ func Cause(err error) error {
|
||||
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
|
||||
|
@ -1,6 +1,7 @@
|
||||
package errors
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"testing"
|
||||
@ -8,7 +9,7 @@ import (
|
||||
|
||||
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 @@ func TestNewError(t *testing.T) {
|
||||
err string
|
||||
want error
|
||||
}{
|
||||
{"", errorString("")},
|
||||
{"foo", errorString("foo")},
|
||||
{"", fmt.Errorf("")},
|
||||
{"foo", fmt.Errorf("foo")},
|
||||
{"foo", New("foo")},
|
||||
}
|
||||
|
||||
@ -42,7 +43,7 @@ type causeError struct {
|
||||
}
|
||||
|
||||
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user