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

Conversation

@davecheney
Copy link
Member

This PR is extracted from #76

This PR is a result of the discussions at GopherCon. The focus of the branch is to decompose Wrap (and Wrapf) into their component operations, namely adding a message, errors.withMessage and adding a stack trace, errors.withStack which were previously merged into one operation with Wrap.

This is accomplished by rewriting Wrap and Wrapf to work in terms of these operations although a small deviation is present to make sure the recorded stack trace is correct.

The motivation for this change was need to treat each of the following operations as distinct:

  • Adding a context message to an existing error without altering the stack trace.
  • Adding a stack trace to an existing error without the requirement adding and additional message.
  • Retrieving the immediate cause of an error; popping one element of the error stack.

Destructure New/Errorf into two components, a call to the stdlib
errors.New or fmt.Errorf to generate a _fundamental_ error, and then a
call to withStack to attach a stack trace to the message.
Introduces WithMessage as well as errors.fundamental, errors.withMessage
and errors.withStack internal types.

Adjust tests for the new wrapped format when combining fundamental and
wrapped errors.
The refactoring to use withStack and withMessage types is useful enough
to land indepdently of exposing these helpers publically.
@davecheney
Copy link
Member Author

/cc FYI @dsnet

@davecheney davecheney merged commit 9cadab9 into master Aug 8, 2016
@davecheney davecheney deleted the withMessage-withStack branch August 8, 2016 04:49
@davecheney davecheney mentioned this pull request Aug 22, 2016
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.

2 participants