rust-lang-deprecated / error-chain

Error boilerplate for Rust
Apache License 2.0
729 stars 111 forks source link

Dealing with multiple threads #227

Open drahnr opened 6 years ago

drahnr commented 6 years ago

How to deal with multiple threads? Especially scoped thread pools are of interest to me.

So far all attempts of implementation ended with

error[E0277]: the trait bound `std::error::Error + 'static: std::marker::Send` is not satisfied
  --> src/main.rs:35:5
   |
35 | /     error_chain!{
36 | |
37 | |         foreign_links {
38 | |             Mqttc(::mqttc::Error);
...  |
53 | |         }
54 | |     }
   | |_____^ `std::error::Error + 'static` cannot be sent between threads safely
   |
   = help: the trait `std::marker::Send` is not implemented for `std::error::Error + 'static`
   = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<std::error::Error + 'static>`
   = note: required because it appears within the type `std::boxed::Box<std::error::Error + 'static>`
   = note: required because it appears within the type `mqttc::netopt::Error`
   = note: required because it appears within the type `mqttc::Error`
   = note: required because it appears within the type `errors::ErrorKind`
   = note: required because it appears within the type `errors::Error`
   = note: required by `error_chain::ChainedError`
   = note: this error originates in a macro outside of the current crate

error: aborting due to previous error(s)

error: Could not compile `mqttblaster`.

Not there is no transfer between the threads. I would like to use one "chain" per thread.

There is nothing in the examples that would show how to deal with this use case.

I also posted this question here: https://stackoverflow.com/questions/46491293/multithreaded-application-fails-to-compile-with-error-chain?noredirect=1#comment79937075_46491293

Yamakaky commented 6 years ago

I think it's because mqttc::Error doesn't impl Send, which error-chain requires.