Rename Stacktrace to StackTrace (#51)
Fixes #50
diff --git a/errors.go b/errors.go
index f2aab6b..817b936 100644
--- a/errors.go
+++ b/errors.go
@@ -51,7 +51,7 @@
// %s print the error. If the error has a Cause it will be
// printed recursively
// %v see %s
-// %+v extended format. Each Frame of the error's Stacktrace will
+// %+v extended format. Each Frame of the error's StackTrace will
// be printed in detail.
//
// Retrieving the stack trace of an error or wrapper
@@ -59,20 +59,20 @@
// New, Errorf, Wrap, and Wrapf record a stack trace at the point they are
// invoked. This information can be retrieved with the following interface.
//
-// type Stacktrace interface {
-// Stacktrace() errors.Stacktrace
+// type StackTrace interface {
+// StackTrace() errors.StackTrace
// }
//
-// Where errors.Stacktrace is defined as
+// Where errors.StackTrace is defined as
//
-// type Stacktrace []Frame
+// type StackTrace []Frame
//
// The Frame type represents a call site in the stacktrace. Frame supports
// the fmt.Formatter interface that can be used for printing information about
// the stacktrace of this error. For example:
//
-// if err, ok := err.(Stacktrace); ok {
-// for _, f := range err.Stacktrace() {
+// if err, ok := err.(StackTrace); ok {
+// for _, f := range err.StackTrace() {
// fmt.Printf("%+s:%d", f)
// }
// }
@@ -99,7 +99,7 @@
case 'v':
if s.Flag('+') {
io.WriteString(s, e.msg)
- fmt.Fprintf(s, "%+v", e.Stacktrace())
+ fmt.Fprintf(s, "%+v", e.StackTrace())
return
}
fallthrough
@@ -145,7 +145,7 @@
case 'v':
if s.Flag('+') {
fmt.Fprintf(s, "%+v\n", w.Cause())
- fmt.Fprintf(s, "%+v: %s", w.Stacktrace()[0], w.msg)
+ fmt.Fprintf(s, "%+v: %s", w.StackTrace()[0], w.msg)
return
}
fallthrough
diff --git a/example_test.go b/example_test.go
index 0f0c80a..f1df234 100644
--- a/example_test.go
+++ b/example_test.go
@@ -120,16 +120,16 @@
}
func Example_stacktrace() {
- type Stacktrace interface {
- Stacktrace() errors.Stacktrace
+ type StackTrace interface {
+ StackTrace() errors.StackTrace
}
- err, ok := errors.Cause(fn()).(Stacktrace)
+ err, ok := errors.Cause(fn()).(StackTrace)
if !ok {
- panic("oops, err does not implement Stacktrace")
+ panic("oops, err does not implement StackTrace")
}
- st := err.Stacktrace()
+ st := err.StackTrace()
fmt.Printf("%+v", st[0:2]) // top two frames
// Example output:
diff --git a/stack.go b/stack.go
index 72a7a6c..243a64a 100644
--- a/stack.go
+++ b/stack.go
@@ -76,10 +76,10 @@
}
}
-// Stacktrace is stack of Frames from innermost (newest) to outermost (oldest).
-type Stacktrace []Frame
+// StackTrace is stack of Frames from innermost (newest) to outermost (oldest).
+type StackTrace []Frame
-func (st Stacktrace) Format(s fmt.State, verb rune) {
+func (st StackTrace) Format(s fmt.State, verb rune) {
switch verb {
case 'v':
switch {
@@ -100,7 +100,7 @@
// stack represents a stack of program counters.
type stack []uintptr
-func (s *stack) Stacktrace() Stacktrace {
+func (s *stack) StackTrace() StackTrace {
f := make([]Frame, len(*s))
for i := 0; i < len(f); i++ {
f[i] = Frame((*s)[i])
diff --git a/stack_test.go b/stack_test.go
index dcc5436..c0488d5 100644
--- a/stack_test.go
+++ b/stack_test.go
@@ -167,30 +167,30 @@
}
}
-func TestStacktrace(t *testing.T) {
+func TestStackTrace(t *testing.T) {
tests := []struct {
err error
want []string
}{{
New("ooh"), []string{
- "github.com/pkg/errors.TestStacktrace\n" +
+ "github.com/pkg/errors.TestStackTrace\n" +
"\t.+/github.com/pkg/errors/stack_test.go:175",
},
}, {
Wrap(New("ooh"), "ahh"), []string{
- "github.com/pkg/errors.TestStacktrace\n" +
+ "github.com/pkg/errors.TestStackTrace\n" +
"\t.+/github.com/pkg/errors/stack_test.go:180", // this is the stack of Wrap, not New
},
}, {
Cause(Wrap(New("ooh"), "ahh")), []string{
- "github.com/pkg/errors.TestStacktrace\n" +
+ "github.com/pkg/errors.TestStackTrace\n" +
"\t.+/github.com/pkg/errors/stack_test.go:185", // this is the stack of New
},
}, {
func() error { return New("ooh") }(), []string{
- `github.com/pkg/errors.(func·005|TestStacktrace.func1)` +
+ `github.com/pkg/errors.(func·005|TestStackTrace.func1)` +
"\n\t.+/github.com/pkg/errors/stack_test.go:190", // this is the stack of New
- "github.com/pkg/errors.TestStacktrace\n" +
+ "github.com/pkg/errors.TestStackTrace\n" +
"\t.+/github.com/pkg/errors/stack_test.go:190", // this is the stack of New's caller
},
}, {
@@ -199,40 +199,40 @@
return Errorf("hello %s", fmt.Sprintf("world"))
}()
}()), []string{
- `github.com/pkg/errors.(func·006|TestStacktrace.func2.1)` +
+ `github.com/pkg/errors.(func·006|TestStackTrace.func2.1)` +
"\n\t.+/github.com/pkg/errors/stack_test.go:199", // this is the stack of Errorf
- `github.com/pkg/errors.(func·007|TestStacktrace.func2)` +
+ `github.com/pkg/errors.(func·007|TestStackTrace.func2)` +
"\n\t.+/github.com/pkg/errors/stack_test.go:200", // this is the stack of Errorf's caller
- "github.com/pkg/errors.TestStacktrace\n" +
+ "github.com/pkg/errors.TestStackTrace\n" +
"\t.+/github.com/pkg/errors/stack_test.go:201", // this is the stack of Errorf's caller's caller
},
}}
for _, tt := range tests {
x, ok := tt.err.(interface {
- Stacktrace() Stacktrace
+ StackTrace() StackTrace
})
if !ok {
- t.Errorf("expected %#v to implement Stacktrace() Stacktrace", tt.err)
+ t.Errorf("expected %#v to implement StackTrace() StackTrace", tt.err)
continue
}
- st := x.Stacktrace()
+ st := x.StackTrace()
for j, want := range tt.want {
testFormatRegexp(t, st[j], "%+v", want)
}
}
}
-func stacktrace() Stacktrace {
+func stacktrace() StackTrace {
const depth = 8
var pcs [depth]uintptr
n := runtime.Callers(1, pcs[:])
var st stack = pcs[0:n]
- return st.Stacktrace()
+ return st.StackTrace()
}
-func TestStacktraceFormat(t *testing.T) {
+func TestStackTraceFormat(t *testing.T) {
tests := []struct {
- Stacktrace
+ StackTrace
format string
want string
}{{
@@ -252,19 +252,19 @@
"%#v",
`\[\]errors.Frame\(nil\)`,
}, {
- make(Stacktrace, 0),
+ make(StackTrace, 0),
"%s",
`\[\]`,
}, {
- make(Stacktrace, 0),
+ make(StackTrace, 0),
"%v",
`\[\]`,
}, {
- make(Stacktrace, 0),
+ make(StackTrace, 0),
"%+v",
"",
}, {
- make(Stacktrace, 0),
+ make(StackTrace, 0),
"%#v",
`\[\]errors.Frame{}`,
}, {
@@ -281,7 +281,7 @@
"\n" +
"github.com/pkg/errors.stacktrace\n" +
"\t.+/github.com/pkg/errors/stack_test.go:228\n" +
- "github.com/pkg/errors.TestStacktraceFormat\n" +
+ "github.com/pkg/errors.TestStackTraceFormat\n" +
"\t.+/github.com/pkg/errors/stack_test.go:279",
}, {
stacktrace()[:2],
@@ -290,6 +290,6 @@
}}
for _, tt := range tests {
- testFormatRegexp(t, tt.Stacktrace, tt.format, tt.want)
+ testFormatRegexp(t, tt.StackTrace, tt.format, tt.want)
}
}