-
-
Notifications
You must be signed in to change notification settings - Fork 150
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
How to make Error cloneable and support context chaining #240
Comments
You haven't implemented a For your use case it sounds like you want In general you would need a |
@dtolnay Awesome, that works. Thank you! For anyone else seeing this, here's the final implementation I use: #[derive(Clone, Error)]
#[error(transparent)]
pub struct AssetError(Arc<anyhow::Error>);
impl From<anyhow::Error> for AssetError {
fn from(err: anyhow::Error) -> Self {
Self(Arc::new(err))
}
}
impl std::fmt::Debug for AssetError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
} |
Just wanted to mention this since I had the same issue: If you're not using thiserror as well as anyhow, instead of using impl std::error::Error for AssetError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.inner.source()
}
} |
Hi,
I have a situation where I need an Error to be Cloneable. I saw #7 and tried implementing something like this:
The one problem though is that it will only store the "latest" two contexts. Any idea how I could change that implementation to store the full context? Here's a playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=2172afa004deb537f4c27d5e7bf54bc3
The text was updated successfully, but these errors were encountered: