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

Commit d7cdef1

Browse files
authored
Remove Fprint (#47)
1 parent 874c0ec commit d7cdef1

File tree

3 files changed

+9
-76
lines changed

3 files changed

+9
-76
lines changed

errors.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,3 @@ func Cause(err error) error {
180180
}
181181
return err
182182
}
183-
184-
// Fprint prints the error to the supplied writer.
185-
// If the error implements the Causer interface described in Cause
186-
// Fprint will recurse into the error's cause.
187-
// Fprint will also print the file and line of the error.
188-
// If err is nil, nothing is printed.
189-
//
190-
// Deprecated: Fprint will be removed in version 0.7.
191-
func Fprint(w io.Writer, err error) {
192-
if err == nil {
193-
return
194-
}
195-
fmt.Fprintf(w, "%+v\n", err)
196-
}

errors_test.go

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package errors
22

33
import (
4-
"bytes"
54
"errors"
65
"fmt"
76
"io"
@@ -95,57 +94,6 @@ func TestCause(t *testing.T) {
9594
}
9695
}
9796

98-
func TestFprintError(t *testing.T) {
99-
x := New("error")
100-
tests := []struct {
101-
err error
102-
want string
103-
}{{
104-
// nil error is nil
105-
err: nil,
106-
}, {
107-
// explicit nil error is nil
108-
err: (error)(nil),
109-
}, {
110-
// uncaused error is unaffected
111-
err: io.EOF,
112-
want: "EOF\n",
113-
}, {
114-
err: Wrap(io.EOF, "cause error"),
115-
want: "EOF\n" +
116-
"github.com/pkg/errors/errors_test.go:114: cause error\n",
117-
}, {
118-
err: x, // return from errors.New
119-
want: "github.com/pkg/errors/errors_test.go:99: error\n",
120-
}, {
121-
err: Wrap(x, "message"),
122-
want: "github.com/pkg/errors/errors_test.go:99: error\n" +
123-
"github.com/pkg/errors/errors_test.go:121: message\n",
124-
}, {
125-
err: Wrap(io.EOF, "message"),
126-
want: "EOF\n" +
127-
"github.com/pkg/errors/errors_test.go:125: message\n",
128-
}, {
129-
err: Wrap(Wrap(x, "message"), "another message"),
130-
want: "github.com/pkg/errors/errors_test.go:99: error\n" +
131-
"github.com/pkg/errors/errors_test.go:129: message\n" +
132-
"github.com/pkg/errors/errors_test.go:129: another message\n",
133-
}, {
134-
err: Wrapf(x, "message"),
135-
want: "github.com/pkg/errors/errors_test.go:99: error\n" +
136-
"github.com/pkg/errors/errors_test.go:134: message\n",
137-
}}
138-
139-
for i, tt := range tests {
140-
var w bytes.Buffer
141-
Fprint(&w, tt.err)
142-
got := w.String()
143-
if got != tt.want {
144-
t.Errorf("test %d: Fprint(w, %q): got %q, want %q", i+1, tt.err, got, tt.want)
145-
}
146-
}
147-
}
148-
14997
func TestWrapfNil(t *testing.T) {
15098
got := Wrapf(nil, "no error")
15199
if got != nil {

example_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package errors_test
22

33
import (
44
"fmt"
5-
"os"
65

76
"github.com/pkg/errors"
87
)
@@ -18,7 +17,7 @@ func ExampleNew_printf() {
1817
err := errors.New("whoops")
1918
fmt.Printf("%+v", err)
2019

21-
// Output: github.com/pkg/errors/example_test.go:18: whoops
20+
// Output: github.com/pkg/errors/example_test.go:17: whoops
2221
}
2322

2423
func ExampleWrap() {
@@ -45,14 +44,14 @@ func ExampleCause() {
4544
// error
4645
}
4746

48-
func ExampleFprint() {
47+
func ExampleCause_printf() {
4948
err := fn()
50-
errors.Fprint(os.Stdout, err)
49+
fmt.Printf("%+v\n", err)
5150

52-
// Output: github.com/pkg/errors/example_test.go:33: error
53-
// github.com/pkg/errors/example_test.go:34: inner
54-
// github.com/pkg/errors/example_test.go:35: middle
55-
// github.com/pkg/errors/example_test.go:36: outer
51+
// Output: github.com/pkg/errors/example_test.go:32: error
52+
// github.com/pkg/errors/example_test.go:33: inner
53+
// github.com/pkg/errors/example_test.go:34: middle
54+
// github.com/pkg/errors/example_test.go:35: outer
5655
}
5756

5857
func ExampleWrapf() {
@@ -67,7 +66,7 @@ func ExampleErrorf() {
6766
err := errors.Errorf("whoops: %s", "foo")
6867
fmt.Printf("%+v", err)
6968

70-
// Output: github.com/pkg/errors/example_test.go:67: whoops: foo
69+
// Output: github.com/pkg/errors/example_test.go:66: whoops: foo
7170
}
7271

7372
func Example_stacktrace() {
@@ -83,5 +82,5 @@ func Example_stacktrace() {
8382
st := err.Stacktrace()
8483
fmt.Printf("%+v", st[0:2]) // top two frames
8584

86-
// Output: [github.com/pkg/errors/example_test.go:33 github.com/pkg/errors/example_test.go:78]
85+
// Output: [github.com/pkg/errors/example_test.go:32 github.com/pkg/errors/example_test.go:77]
8786
}

0 commit comments

Comments
 (0)