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

Commit 73d71e4

Browse files
authored
Rename Stacktrace to StackTrace (#51)
Fixes #50
1 parent 784931b commit 73d71e4

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

errors.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,28 @@
5151
// %s print the error. If the error has a Cause it will be
5252
// printed recursively
5353
// %v see %s
54-
// %+v extended format. Each Frame of the error's Stacktrace will
54+
// %+v extended format. Each Frame of the error's StackTrace will
5555
// be printed in detail.
5656
//
5757
// Retrieving the stack trace of an error or wrapper
5858
//
5959
// New, Errorf, Wrap, and Wrapf record a stack trace at the point they are
6060
// invoked. This information can be retrieved with the following interface.
6161
//
62-
// type Stacktrace interface {
63-
// Stacktrace() errors.Stacktrace
62+
// type StackTrace interface {
63+
// StackTrace() errors.StackTrace
6464
// }
6565
//
66-
// Where errors.Stacktrace is defined as
66+
// Where errors.StackTrace is defined as
6767
//
68-
// type Stacktrace []Frame
68+
// type StackTrace []Frame
6969
//
7070
// The Frame type represents a call site in the stacktrace. Frame supports
7171
// the fmt.Formatter interface that can be used for printing information about
7272
// the stacktrace of this error. For example:
7373
//
74-
// if err, ok := err.(Stacktrace); ok {
75-
// for _, f := range err.Stacktrace() {
74+
// if err, ok := err.(StackTrace); ok {
75+
// for _, f := range err.StackTrace() {
7676
// fmt.Printf("%+s:%d", f)
7777
// }
7878
// }
@@ -99,7 +99,7 @@ func (e _error) Format(s fmt.State, verb rune) {
9999
case 'v':
100100
if s.Flag('+') {
101101
io.WriteString(s, e.msg)
102-
fmt.Fprintf(s, "%+v", e.Stacktrace())
102+
fmt.Fprintf(s, "%+v", e.StackTrace())
103103
return
104104
}
105105
fallthrough
@@ -145,7 +145,7 @@ func (w wrapper) Format(s fmt.State, verb rune) {
145145
case 'v':
146146
if s.Flag('+') {
147147
fmt.Fprintf(s, "%+v\n", w.Cause())
148-
fmt.Fprintf(s, "%+v: %s", w.Stacktrace()[0], w.msg)
148+
fmt.Fprintf(s, "%+v: %s", w.StackTrace()[0], w.msg)
149149
return
150150
}
151151
fallthrough

example_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,16 @@ func ExampleErrorf_extended() {
120120
}
121121

122122
func Example_stacktrace() {
123-
type Stacktrace interface {
124-
Stacktrace() errors.Stacktrace
123+
type StackTrace interface {
124+
StackTrace() errors.StackTrace
125125
}
126126

127-
err, ok := errors.Cause(fn()).(Stacktrace)
127+
err, ok := errors.Cause(fn()).(StackTrace)
128128
if !ok {
129-
panic("oops, err does not implement Stacktrace")
129+
panic("oops, err does not implement StackTrace")
130130
}
131131

132-
st := err.Stacktrace()
132+
st := err.StackTrace()
133133
fmt.Printf("%+v", st[0:2]) // top two frames
134134

135135
// Example output:

stack.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ func (f Frame) Format(s fmt.State, verb rune) {
7676
}
7777
}
7878

79-
// Stacktrace is stack of Frames from innermost (newest) to outermost (oldest).
80-
type Stacktrace []Frame
79+
// StackTrace is stack of Frames from innermost (newest) to outermost (oldest).
80+
type StackTrace []Frame
8181

82-
func (st Stacktrace) Format(s fmt.State, verb rune) {
82+
func (st StackTrace) Format(s fmt.State, verb rune) {
8383
switch verb {
8484
case 'v':
8585
switch {
@@ -100,7 +100,7 @@ func (st Stacktrace) Format(s fmt.State, verb rune) {
100100
// stack represents a stack of program counters.
101101
type stack []uintptr
102102

103-
func (s *stack) Stacktrace() Stacktrace {
103+
func (s *stack) StackTrace() StackTrace {
104104
f := make([]Frame, len(*s))
105105
for i := 0; i < len(f); i++ {
106106
f[i] = Frame((*s)[i])

stack_test.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -167,30 +167,30 @@ func TestTrimGOPATH(t *testing.T) {
167167
}
168168
}
169169

170-
func TestStacktrace(t *testing.T) {
170+
func TestStackTrace(t *testing.T) {
171171
tests := []struct {
172172
err error
173173
want []string
174174
}{{
175175
New("ooh"), []string{
176-
"github.com/pkg/errors.TestStacktrace\n" +
176+
"github.com/pkg/errors.TestStackTrace\n" +
177177
"\t.+/github.com/pkg/errors/stack_test.go:175",
178178
},
179179
}, {
180180
Wrap(New("ooh"), "ahh"), []string{
181-
"github.com/pkg/errors.TestStacktrace\n" +
181+
"github.com/pkg/errors.TestStackTrace\n" +
182182
"\t.+/github.com/pkg/errors/stack_test.go:180", // this is the stack of Wrap, not New
183183
},
184184
}, {
185185
Cause(Wrap(New("ooh"), "ahh")), []string{
186-
"github.com/pkg/errors.TestStacktrace\n" +
186+
"github.com/pkg/errors.TestStackTrace\n" +
187187
"\t.+/github.com/pkg/errors/stack_test.go:185", // this is the stack of New
188188
},
189189
}, {
190190
func() error { return New("ooh") }(), []string{
191-
`github.com/pkg/errors.(func·005|TestStacktrace.func1)` +
191+
`github.com/pkg/errors.(func·005|TestStackTrace.func1)` +
192192
"\n\t.+/github.com/pkg/errors/stack_test.go:190", // this is the stack of New
193-
"github.com/pkg/errors.TestStacktrace\n" +
193+
"github.com/pkg/errors.TestStackTrace\n" +
194194
"\t.+/github.com/pkg/errors/stack_test.go:190", // this is the stack of New's caller
195195
},
196196
}, {
@@ -199,40 +199,40 @@ func TestStacktrace(t *testing.T) {
199199
return Errorf("hello %s", fmt.Sprintf("world"))
200200
}()
201201
}()), []string{
202-
`github.com/pkg/errors.(func·006|TestStacktrace.func2.1)` +
202+
`github.com/pkg/errors.(func·006|TestStackTrace.func2.1)` +
203203
"\n\t.+/github.com/pkg/errors/stack_test.go:199", // this is the stack of Errorf
204-
`github.com/pkg/errors.(func·007|TestStacktrace.func2)` +
204+
`github.com/pkg/errors.(func·007|TestStackTrace.func2)` +
205205
"\n\t.+/github.com/pkg/errors/stack_test.go:200", // this is the stack of Errorf's caller
206-
"github.com/pkg/errors.TestStacktrace\n" +
206+
"github.com/pkg/errors.TestStackTrace\n" +
207207
"\t.+/github.com/pkg/errors/stack_test.go:201", // this is the stack of Errorf's caller's caller
208208
},
209209
}}
210210
for _, tt := range tests {
211211
x, ok := tt.err.(interface {
212-
Stacktrace() Stacktrace
212+
StackTrace() StackTrace
213213
})
214214
if !ok {
215-
t.Errorf("expected %#v to implement Stacktrace() Stacktrace", tt.err)
215+
t.Errorf("expected %#v to implement StackTrace() StackTrace", tt.err)
216216
continue
217217
}
218-
st := x.Stacktrace()
218+
st := x.StackTrace()
219219
for j, want := range tt.want {
220220
testFormatRegexp(t, st[j], "%+v", want)
221221
}
222222
}
223223
}
224224

225-
func stacktrace() Stacktrace {
225+
func stacktrace() StackTrace {
226226
const depth = 8
227227
var pcs [depth]uintptr
228228
n := runtime.Callers(1, pcs[:])
229229
var st stack = pcs[0:n]
230-
return st.Stacktrace()
230+
return st.StackTrace()
231231
}
232232

233-
func TestStacktraceFormat(t *testing.T) {
233+
func TestStackTraceFormat(t *testing.T) {
234234
tests := []struct {
235-
Stacktrace
235+
StackTrace
236236
format string
237237
want string
238238
}{{
@@ -252,19 +252,19 @@ func TestStacktraceFormat(t *testing.T) {
252252
"%#v",
253253
`\[\]errors.Frame\(nil\)`,
254254
}, {
255-
make(Stacktrace, 0),
255+
make(StackTrace, 0),
256256
"%s",
257257
`\[\]`,
258258
}, {
259-
make(Stacktrace, 0),
259+
make(StackTrace, 0),
260260
"%v",
261261
`\[\]`,
262262
}, {
263-
make(Stacktrace, 0),
263+
make(StackTrace, 0),
264264
"%+v",
265265
"",
266266
}, {
267-
make(Stacktrace, 0),
267+
make(StackTrace, 0),
268268
"%#v",
269269
`\[\]errors.Frame{}`,
270270
}, {
@@ -281,7 +281,7 @@ func TestStacktraceFormat(t *testing.T) {
281281
"\n" +
282282
"github.com/pkg/errors.stacktrace\n" +
283283
"\t.+/github.com/pkg/errors/stack_test.go:228\n" +
284-
"github.com/pkg/errors.TestStacktraceFormat\n" +
284+
"github.com/pkg/errors.TestStackTraceFormat\n" +
285285
"\t.+/github.com/pkg/errors/stack_test.go:279",
286286
}, {
287287
stacktrace()[:2],
@@ -290,6 +290,6 @@ func TestStacktraceFormat(t *testing.T) {
290290
}}
291291

292292
for _, tt := range tests {
293-
testFormatRegexp(t, tt.Stacktrace, tt.format, tt.want)
293+
testFormatRegexp(t, tt.StackTrace, tt.format, tt.want)
294294
}
295295
}

0 commit comments

Comments
 (0)