You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Introduce Stacktrace and Frame
This PR is a continuation of a series aimed at exposing the stack trace
information embedded in each error value. The secondary effect is to
deprecated the `Fprintf` helper.
Taking cues from from @ChrisHines' `stack` package this PR introduces a
new interface `Stacktrace() []Frame` and a `Frame` type, similar in
function to the `runtime.Frame` type (although lacking its iterator
type). Each `Frame` implemnts `fmt.Formatter` allowing it to print
itself.
The older `Location` interface is still supported but also deprecated.
Copy file name to clipboardExpand all lines: README.md
+11-2Lines changed: 11 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,10 +24,19 @@ if err != nil {
24
24
`New`, `Errorf`, `Wrap`, and `Wrapf` record a stack trace at the point they are invoked.
25
25
This information can be retrieved with the following interface.
26
26
```go
27
-
typeStackinterface {
28
-
Stack() []uintptr
27
+
typeStacktraceinterface {
28
+
Stacktrace() []Frame
29
29
}
30
30
```
31
+
The `Frame` type represents a call site in the stacktrace.
32
+
`Frame` supports the `fmt.Formatter` interface that can be used for printing information about the stacktrace of this error. For example
33
+
```
34
+
if err, ok := err.(Stacktrace); ok {
35
+
fmt.Printf("%+s:%d", err.Stacktrace())
36
+
}
37
+
```
38
+
See [the documentation for `Frame.Format`](https://godoc.org/github.com/pkg/errors#Frame_Format) for more details.
39
+
31
40
## Retrieving the cause of an error
32
41
33
42
Using `errors.Wrap` constructs a stack of errors, adding context to the preceding error. Depending on the nature of the error it may be necessary to recurse the operation of errors.Wrap to retrieve the original error for inspection. Any error value which implements this interface can be inspected by `errors.Cause`.
0 commit comments