-
Notifications
You must be signed in to change notification settings - Fork 339
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
verbose errors feature #551
verbose errors feature #551
Conversation
This adds a new "verbose-errors" feature flag to async-std that enables wrapping certain errors in structures with more context. As an example, we use it in `fs::File::{open,create}` to add the given path to the error message (something that is lacking in std to annoyance of many).
We discussed this a while back, and I wanted to provide something small that can be a basis for discussion. The main thing here is to provide an internal mechanism to easily add optional contexts. I hope–but have not proven–that the closure get compiled away in release modes without the feature flag set. |
This is great, thank you! :) I think we don't even need to introduce a new feature flag for this and can just provide verbose errors by default. Is there any real downside to providing this by default? Wdyt, @yoshuawuyts ? |
It costs a string allocation in the error case 🤷 |
Error cases don't need to be fast :) Besides, we already have a string allocation for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall very excited for this direction, and don't think we need a feature to introduce this.
Left some nits on naming, but otherwise this is great!
a9f134d
to
35356a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated: Now without feature flag!
use std::{error::Error as StdError, fmt, io}; | ||
|
||
#[derive(Debug)] | ||
pub(crate) struct VerboseError { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure this type could be using source: T
but let's refactor this when we have a use case
35356a7
to
c704643
Compare
This adds a new "verbose-errors" feature flag to async-std that enables
wrapping certain errors in structures with more context. As an example,
we use it in
fs::File::{open,create}
to add the given path to theerror message (something that is lacking in std to annoyance of many).