Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print the stack trace when formatting with %+v #26

Closed
wants to merge 2 commits into from

Conversation

mkmik
Copy link
Contributor

@mkmik mkmik commented Jun 16, 2016

Discovered in:
http://dave.cheney.net/2016/06/12/stack-traces-and-the-errors-package

Code based on:
https://github.com/pkg/errors

With a minor but hackish change to still allow %#v to print the structure fields, in order to not break the principle of least surprise. Let me know if there is a better way to strip a type of an interface or invoke the default %#v behaviour on a type that implements fmt.Formatter.

@mjs
Copy link

mjs commented Sep 14, 2016

Thanks for this. LGTM but I'll leave the final verdict to @howbazaar

}

// helper for Format
type unformatter Err
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why this is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@howbazaar because otherwise fmt.Fprintf(s, "%#v", e) would yield an infinite recursion.

Any better idea to achieve the same formatting of %#v without re-entering the Format method?

@mkmik
Copy link
Contributor Author

mkmik commented Jan 19, 2017

moving to #28 due to organization membership change

@mkmik mkmik closed this Jan 19, 2017
jujubot added a commit that referenced this pull request May 9, 2017
Print the stack trace when formatting with %+v

Discovered in:
http://dave.cheney.net/2016/06/12/stack-traces-and-the-errors-package

Code based on:
https://github.com/pkg/errors

With a minor but hackish change to still allow %#v to print the structure fields, in order to not break the principle of least surprise. Let me know if there is a better way to strip a type of an interface or invoke the default %#v behaviour on a type that implements fmt.Formatter.

---

NOTE: this is the continuation of #26. I no longer work for cesanta and thus cannot address comments in the original PR.

#26 received the green light from @mjs, and had an open question by @howbazaar, whom I replied to.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants