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

Proposal: output stack trace if debugging is enabled #96

Closed
cyphar opened this issue Dec 16, 2016 · 6 comments
Closed

Proposal: output stack trace if debugging is enabled #96

cyphar opened this issue Dec 16, 2016 · 6 comments

Comments

@cyphar
Copy link

cyphar commented Dec 16, 2016

In other words, it should be possible for a user at runtime to provide a --debug flag to a binary and then the binary should be able to easily make any error output a stack trace.

The nicest way of doing this (IMO) would be to have something like logrus.LogLevel (except it would be something like errors.EmitStack(bool) that would determine whether "%s" and similar format strings will output a stack trace.

Currently an application writer has to make a decision whether they will make their program debuggable (use %+v everywhere) or helpful to users (use %s everywhere).

@cyphar
Copy link
Author

cyphar commented Dec 16, 2016

#97 is my implementation of this.

@davecheney
Copy link
Member

davecheney commented Dec 17, 2016 via email

@cyphar
Copy link
Author

cyphar commented Dec 18, 2016 via email

@loren-osborn
Copy link

@davecheney, I’m mostly thinking out loud here, and haven’t thought as far as an API yet, but I’m wondering if a cascading priority makes sense:

  • If the caller chooses to render the error with or without a stack trace explicitly, that is always honored.
  • If the caller uses default error rendering, but the error itself (based on options when the error was created) prefers to be rendered with or without a stack trace explicitly, that is how the error is rendered.
  • If neither the caller nor the error specify if they want a stack trace, a global default, (similar to Proposal: output stack trace if debugging is enabled #96 / errors: add Debug() function #97) determines if the error renders a stack trace.

As I indicated above, these are just ideas I had reviewing old PRs. I’d be interested to hear your opinions.

@davecheney
Copy link
Member

Thank you for your comment. My position has not changed since my last comment.

@cyphar
Copy link
Author

cyphar commented Oct 24, 2018

Within umoci I've just decided to use %+v if debugging is enabled. This works for me since everything goes through a single CLI library, but maybe others want this. Closing.

@cyphar cyphar closed this as completed Oct 24, 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

No branches or pull requests

3 participants