Skip to content
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

#[source] does not work on Box<dyn Error + Send + Sync> #272

Closed
bennetthardwick opened this issue Jun 16, 2023 · 0 comments · Fixed by #273
Closed

#[source] does not work on Box<dyn Error + Send + Sync> #272

bennetthardwick opened this issue Jun 16, 2023 · 0 comments · Fixed by #273

Comments

@bennetthardwick
Copy link
Contributor

In order to get miette (with thiserror) to render the full error chain I need to be able to add the #[source] macro onto the "source" error.

In my project I'm using a boxed error that also needs to be Send + Sync like so:

#[derive(Diagnostic, Error)]
struct MyError {
  #[error("Any Error")]
  #[diagnostic(transparent)]
  AnyError(#[source] Box<dyn Diagnostic + Send + Sync>)
}

However that example fails with the following compilation error:

error[E0599]: the method `as_dyn_error` exists for reference `&Box<dyn Diagnostic + Send + Sync>`, but its trait bounds were not satisfied

20  |   pub trait Diagnostic: std::error::Error {
    |   ---------------------------------------
    |   |
    |   doesn't satisfy `dyn Diagnostic + Send + Sync: AsDynError<'_>`
    |   doesn't satisfy `dyn Diagnostic + Send + Sync: Sized`

I was able to get around the issue by using an Arc instead of a Box - but I don't need any Arc features so it would be great if it worked with Box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant