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

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
4 participants
Contributor

mmikulicic 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 commented Sep 14, 2016

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

+}
+
+// helper for Format
+type unformatter Err
@howbazaar

howbazaar Sep 14, 2016

Owner

I don't understand why this is necessary?

@mmikulicic

mmikulicic Jan 19, 2017

Contributor

@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?

Contributor

mmikulicic commented Jan 19, 2017

moving to #28 due to organization membership change

@mmikulicic mmikulicic closed this Jan 19, 2017

jujubot added a commit that referenced this pull request May 9, 2017

Merge pull request #28 from mmikulicic/master
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