-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
Conflicting ergonomics for source chains #214
Comments
I attempted implementing let result: std::fmt::Result = { #body };
if let e@Err(_) = result {
return e;
}
if __formatter.alternate() {
let mut next = <Self as std::error::Error>::source(self);
while let Some(source) = next {
write!(__formatter, ": {}", source)?;
next = source.source();
}
}
Ok(()) but that fails for this test case: #[derive(Error, Debug)]
#[error(transparent)]
pub struct StructTransparentGeneric<E>(E); because |
This is the main reason why I've started returning For this to make sense though I've also had to clean up stray So, while at it, is it possible/reasonable to look into providing a similar |
Looks like there are more issues open on the topic of merge ergonomic/consistent source chain formatting (especially when considering |
Closing in favor of #98. |
For errors defined by context information and an inner source, we usually want to display both the context and the source to the user.
thiserror
makes this convenient through annotations like#[error("{context}: {source}")]
. However, this pattern will lead to ugly and confusing duplication of information when combined withanyhow
's handy feature to format source chains automatically. On the other hand, using something like#[error("{context}")]
leads to worse behavior for users who invoke the error'sDisplay
impl directly rather than going throughanyhow
.anyhow
is very popular, but it is also reasonable to expect crucial details to beDisplay
able without requiring custom traversal code. How can we resolve this conflict?One idea is for
thiserror
itself to provide a convenient interface for traversing source chains. Maybe this could be an inherent method, or exposed through the alternateDisplay
mode ({:#}
) as done byanyhow
, giving consistentDisplay
behavior across both crates.The text was updated successfully, but these errors were encountered: