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

Introduce Stacktrace and Frame #37

Merged
merged 2 commits into from
Jun 7, 2016
Merged

Introduce Stacktrace and Frame #37

merged 2 commits into from
Jun 7, 2016

Conversation

davecheney
Copy link
Member

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.

@davecheney davecheney force-pushed the stacktrace branch 4 times, most recently from 560e9b0 to 33bc92c Compare June 6, 2016 22:29
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.
fmt.Fprintf(s, "%d", f.line())
case 'n':
name := runtime.FuncForPC(f.pc()).Name()
i := strings.LastIndex(name, ".")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that for a method name will look like package-path.type-name.method-name. Using LastIndex(name, ".") excludes the type-name, which would be ambiguous when many methods have the same name. That is why the stack package finds the first . after the last /.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I cheated there. I'll try to write a test case and fix this.

- Handle possible nil in `runtime.FuncForPC`
- Refactor trimGOPATH to work on strings, not funcs and pc's
- Fix incorrect handling of `%n` for methods.
@davecheney davecheney merged commit 3cdd332 into master Jun 7, 2016
@davecheney davecheney deleted the stacktrace branch June 7, 2016 04:23
@philoserf philoserf mentioned this pull request Jan 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants