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

Extended stacktrace output #49

Merged
merged 6 commits into from
Jun 11, 2016
Merged

Extended stacktrace output #49

merged 6 commits into from
Jun 11, 2016

Conversation

davecheney
Copy link
Member

@davecheney davecheney commented Jun 10, 2016

This PR introduces an "extended" stacktrace output to this package's error implementation controlled by the %+v verb.

An example of the %+v syntax, taken from ExampleWrap

hello world
github.com/pkg/errors_test.ExampleCause_extended.func1.1
        /home/dfc/src/github.com/pkg/errors/example_test.go:156
github.com/pkg/errors_test.ExampleCause_extended.func1
        /home/dfc/src/github.com/pkg/errors/example_test.go:157
github.com/pkg/errors_test.ExampleCause_extended
        /home/dfc/src/github.com/pkg/errors/example_test.go:158
testing.runExample
        /home/dfc/go/src/testing/example.go:114
testing.RunExamples
        /home/dfc/go/src/testing/example.go:38
testing.(*M).Run
        /home/dfc/go/src/testing/testing.go:744
main.main
        github.com/pkg/errors/_test/_testmain.go:104
runtime.main
        /home/dfc/go/src/runtime/proc.go:183
runtime.goexit
        /home/dfc/go/src/runtime/asm_amd64.s:2059
github.com/pkg/errors_test.ExampleCause_extended
        /home/dfc/src/github.com/pkg/errors/example_test.go:158: failed

The output takes some explaining.

  • The first line hello world is the original text passed to errors.Errorf
  • The second til the third to last are the stacktrace recorded at the time errors.Errorf was invoked.
  • The Last two lines are the stack trace at the point errors.Wrap was called to wrap the previous error with the additional text failed. The stacktrace is not printed in this case, only the point at which the caller was invoked. Printing the additional stack trace is subject for further debate.

The PR is large, but that is due to the large impact it has on the tested output, the actual change to errors.go is 3 lines.

@davecheney
Copy link
Member Author

The tests are failing because I (stupidly) used the paths to my local gopath in the fixtures. I'll fix it tomorrow.

@davecheney
Copy link
Member Author

/cc @ChrisHines all the tests pass again, ready for review.

@davecheney davecheney merged commit 7896481 into master Jun 11, 2016
@davecheney davecheney deleted the stacktrace branch June 11, 2016 13:04
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.

1 participant