From d7cdef1704d56fbd200fb2ae55cd7d3aede0c953 Mon Sep 17 00:00:00 2001 From: Dave Cheney Date: Fri, 10 Jun 2016 11:53:11 +1000 Subject: [PATCH] Remove Fprint (#47) --- errors.go | 14 ------------- errors_test.go | 52 ------------------------------------------------- example_test.go | 19 +++++++++--------- 3 files changed, 9 insertions(+), 76 deletions(-) diff --git a/errors.go b/errors.go index 0261282..a31ca30 100644 --- a/errors.go +++ b/errors.go @@ -180,17 +180,3 @@ func Cause(err error) error { } return err } - -// Fprint prints the error to the supplied writer. -// If the error implements the Causer interface described in Cause -// Fprint will recurse into the error's cause. -// Fprint will also print the file and line of the error. -// If err is nil, nothing is printed. -// -// Deprecated: Fprint will be removed in version 0.7. -func Fprint(w io.Writer, err error) { - if err == nil { - return - } - fmt.Fprintf(w, "%+v\n", err) -} diff --git a/errors_test.go b/errors_test.go index ac58ec3..11d4555 100644 --- a/errors_test.go +++ b/errors_test.go @@ -1,7 +1,6 @@ package errors import ( - "bytes" "errors" "fmt" "io" @@ -95,57 +94,6 @@ func TestCause(t *testing.T) { } } -func TestFprintError(t *testing.T) { - x := New("error") - tests := []struct { - err error - want string - }{{ - // nil error is nil - err: nil, - }, { - // explicit nil error is nil - err: (error)(nil), - }, { - // uncaused error is unaffected - err: io.EOF, - want: "EOF\n", - }, { - err: Wrap(io.EOF, "cause error"), - want: "EOF\n" + - "github.com/pkg/errors/errors_test.go:114: cause error\n", - }, { - err: x, // return from errors.New - want: "github.com/pkg/errors/errors_test.go:99: error\n", - }, { - err: Wrap(x, "message"), - want: "github.com/pkg/errors/errors_test.go:99: error\n" + - "github.com/pkg/errors/errors_test.go:121: message\n", - }, { - err: Wrap(io.EOF, "message"), - want: "EOF\n" + - "github.com/pkg/errors/errors_test.go:125: message\n", - }, { - err: Wrap(Wrap(x, "message"), "another message"), - want: "github.com/pkg/errors/errors_test.go:99: error\n" + - "github.com/pkg/errors/errors_test.go:129: message\n" + - "github.com/pkg/errors/errors_test.go:129: another message\n", - }, { - err: Wrapf(x, "message"), - want: "github.com/pkg/errors/errors_test.go:99: error\n" + - "github.com/pkg/errors/errors_test.go:134: message\n", - }} - - for i, tt := range tests { - var w bytes.Buffer - Fprint(&w, tt.err) - got := w.String() - if got != tt.want { - t.Errorf("test %d: Fprint(w, %q): got %q, want %q", i+1, tt.err, got, tt.want) - } - } -} - func TestWrapfNil(t *testing.T) { got := Wrapf(nil, "no error") if got != nil { diff --git a/example_test.go b/example_test.go index 329c1cd..c2b74f8 100644 --- a/example_test.go +++ b/example_test.go @@ -2,7 +2,6 @@ package errors_test import ( "fmt" - "os" "github.com/pkg/errors" ) @@ -18,7 +17,7 @@ func ExampleNew_printf() { err := errors.New("whoops") fmt.Printf("%+v", err) - // Output: github.com/pkg/errors/example_test.go:18: whoops + // Output: github.com/pkg/errors/example_test.go:17: whoops } func ExampleWrap() { @@ -45,14 +44,14 @@ func ExampleCause() { // error } -func ExampleFprint() { +func ExampleCause_printf() { err := fn() - errors.Fprint(os.Stdout, err) + fmt.Printf("%+v\n", err) - // Output: github.com/pkg/errors/example_test.go:33: error - // github.com/pkg/errors/example_test.go:34: inner - // github.com/pkg/errors/example_test.go:35: middle - // github.com/pkg/errors/example_test.go:36: outer + // Output: github.com/pkg/errors/example_test.go:32: error + // github.com/pkg/errors/example_test.go:33: inner + // github.com/pkg/errors/example_test.go:34: middle + // github.com/pkg/errors/example_test.go:35: outer } func ExampleWrapf() { @@ -67,7 +66,7 @@ func ExampleErrorf() { err := errors.Errorf("whoops: %s", "foo") fmt.Printf("%+v", err) - // Output: github.com/pkg/errors/example_test.go:67: whoops: foo + // Output: github.com/pkg/errors/example_test.go:66: whoops: foo } func Example_stacktrace() { @@ -83,5 +82,5 @@ func Example_stacktrace() { st := err.Stacktrace() fmt.Printf("%+v", st[0:2]) // top two frames - // Output: [github.com/pkg/errors/example_test.go:33 github.com/pkg/errors/example_test.go:78] + // Output: [github.com/pkg/errors/example_test.go:32 github.com/pkg/errors/example_test.go:77] }