You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I would like to be able to downcast on the just the topmost layer of the context stack. Looking through the API, it doesn't appear that this is possible. It's nearly possible by using the underlying std::error::Error provided downcasting, instead of the anyhow downcasting, but anyhow wraps the context in a private ContextError. Even if it were public, I still don't think it would be possible since I know the C context type I want, but not the E error type.
I think I can work around this in a good enough way for my usecase by comparing my_anyhow_error.downcast_ref::<MyType>().unwrap().to_string() to my_anyhow_error.to_string(), which gives me a pretty good indication that the first instance of MyType in the stack is the topmost context layer, but I'm curious if it might be a generally useful feature for anyhow.
The text was updated successfully, but these errors were encountered:
Maybe in addition to the downcast_ref method there could be a downcast_context method that gives you a reference to the context if there is one and downcasting the context succeeded?
My workaround was to create a new error type with a cause field that points to the original anyhow::Error, but that seems undesirable as I now have multiple box layers in the errors. Basically I want https://docs.rs/anyhow/1.0.31/anyhow/trait.Context.html#effect-on-downcasting to work, but that doesn't work for me (maybe that demo requires an Option instead of a Result?).
Hi, I would like to be able to downcast on the just the topmost layer of the context stack. Looking through the API, it doesn't appear that this is possible. It's nearly possible by using the underlying std::error::Error provided downcasting, instead of the anyhow downcasting, but anyhow wraps the context in a private ContextError. Even if it were public, I still don't think it would be possible since I know the
C
context type I want, but not theE
error type.I think I can work around this in a good enough way for my usecase by comparing
my_anyhow_error.downcast_ref::<MyType>().unwrap().to_string()
tomy_anyhow_error.to_string()
, which gives me a pretty good indication that the first instance of MyType in the stack is the topmost context layer, but I'm curious if it might be a generally useful feature for anyhow.The text was updated successfully, but these errors were encountered: