error-stack: method cannot be called due to unsatisfied trait bounds
#2659
-
First, thank you for the lib. I'm new to
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hi @jmakov and thanks for opening this. The issue is most likely that your impl<C: Error + Send + Sync + 'static> Context for C {
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
Error::provide(self, demand);
}
} Will changing the |
Beta Was this translation helpful? Give feedback.
-
Hey. Thanks again for answering the question. As someone new to this lib it's frustrating to hit the wall. So this is my custom error:
And the method where this occurs has the signature |
Beta Was this translation helpful? Give feedback.
-
I took a deeper look at your error message and it seems that you're using the pub struct MyError(Box<dyn Error + Send + Sync>);
impl fmt::Debug for MyError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&*self.0, f)
}
}
impl fmt::Display for MyError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&*self.0, f)
}
}
impl Error for MyError {}
fn creates_boxed_error() -> Result<(), Box<dyn Error + Send + Sync>> {
Ok(())
}
fn consumes_boxed_error() -> Result<(), Report<MyError>> {
creates_boxed_error().map_err(MyError).into_report()?;
Ok(())
} |
Beta Was this translation helpful? Give feedback.
I took a deeper look at your error message and it seems that you're using the
fastwebsockets
crate. I'm not going to judge their library design, but generally, returningBox<dyn Error + Send + Sync>
is bad practice, especially for a library function. This makes it very hard to deal with errors as an application. the only real way to make the error usable again is something like: