-
Notifications
You must be signed in to change notification settings - Fork 60
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
Support additional ways of specifying the error source or backtrace #10
Comments
Should the inner error be optional? Right now you get a compile error if you don't have one. |
I’m not sure I’m following. If you don’t include a Do you mean optional as in |
In your words :-):
I didn't notice that, and this error got me a little confused, because it's not exactly clear what the issue is:
I'm not saying you should make that code work, it's just a thing I ran into. |
I have a usecase but maybe I have the wrong idea #[derive(Debug, Snafu)]
#[snafu(display("{website}:\n {kind}"))]
pub struct WebsiteError {
website: SupportedSites,
kind: WebsiteErrorKind,
source: fantoccini::error::CmdError,
}
#[derive(Debug, Snafu)]
pub enum WebsiteErrorKind {
#[snafu(display("the query matched 0 elements on the page.\n query: '{query}'"))]
QuerySelectorAll { query: String },
#[snafu(display(
"the query only matched {img_count} <img />s when {page_count} were expected.\n query: '{query}'"
))]
MissingImagesAfterMaxRetries {
img_count: usize,
page_count: usize,
query: String,
},
} then I can do this: // Result<Vec<Element>, fantoccini::error::CmdError>
let imgs = self.find_all(Locator::Css(&query)).await.context(WebsiteSnafu {
website: SupportedSites::MangaFire,
kind: WebsiteErrorKind::QuerySelectorAll { query },
})?; but now you cant return errors that dont need a source // error[E0063]: missing field `source` in initializer of `WebsiteError`
return Err(WebsiteError {
website: SupportedSites::MangaFire,
kind: WebsiteErrorKind::QuerySelectorAll { query },
}); ideally you could make // only provides a source if .context is used
#[derive(Debug, Snafu)]
#[snafu(display("{website}:\n {kind}"))]
pub struct WebsiteError {
website: SupportedSites,
kind: WebsiteErrorKind,
source: Option<fantoccini::error::CmdError>,
} |
Right now, we only support an underlying error denoted by the field named
source
and a backtrace by the namebacktrace
. We should also support a field attribute (#[snafu(source)]
/#[snafu(backtrace)]
), with an optional boolean to disable the automatic (#[snafu(source(false))]
/#[snafu(backtrace(false))]
)Precedence wise, it should be:
source
The text was updated successfully, but these errors were encountered: