error-chain
error-chain copied to clipboard
Using error-chain with boxed errors
Hello, I have an API which returns a Result<(),Box<std::error::Error + Sync + Send + 'static>>, and I'd like to chain on that. However, I get this error:
error: no method named `chain_err` found for type `std::result::Result<(), std::boxed::Box<std::error::Error + std::marker::Send + std::marker::Sync + 'static>>` in the current scope
--> src/engine.rs:408:30
|
408 | .chain_err(|| ErrorKind::BoxedIntegrationError)?
| ^^^^^^^^^
|
= note: the method `chain_err` exists but the following trait bounds were not satisfied:
`std::boxed::Box<std::error::Error + std::marker::Send + std::marker::Sync> : std::error::Error`
= help: items from traits can only be used if the trait is implemented and in scope; the following trait defines an item `chain_err`, perhaps you need to implement it:
= help: candidate #1: `errors::ResultExt`
Any ideas on how to approach this? The API is 3rd party, so I can't modify it to return a specific error--it must be the boxed trait.
Sorry for the delay. Could you give more code?
Here's a minimal case. It should be possible to chain with results that contain boxed errors, but it isn't. Note that demo fails due to the Err variant being boxed, but of course other works fine.
#[macro_use]
extern crate error_chain;
pub mod errors {
error_chain! {
}
}
use errors::*;
fn demo(input: std::result::Result<(),Box<std::error::Error + Sync + Send + 'static>>) -> Result<()> {
input.chain_err(|| "fails")
}
fn other(input: Result<()>) -> Result<()> {
input.chain_err(|| "fine")
}
Do you want to try an implementation?
See also #69, if you want to do that too.