How to use error_chain with generic error types?


I’m trying to use the error_chain library with the std::sync::mpsc queues. I’d like to have the SendError be a foreign_link so that I can use it with .chain_err(), but I’m not sure if there’s any way to specify the foreign link with the generic parameter intact. My code is itself a library that is parameterized by the same type that would parameterize the SendError, which is why I don’t know it in advance.

Thank you!


It should can! But may be crate error-chain has not support this.

Therefor, my solution is ugly:

I think error-chain can support type params by defaulted-type-params.


I haven’t see that custom derive syntax before–is that a part of the error_chain library? Where is it documented?


I found custom in another crate called derive-error-chain,

It said:

extern crate derive_error_chain

#[error_chain(description = r#"|_| "invalid toolchain name""#)]
#[error_chain(display = r#"|t| write!(f, "invalid toolchain name: '{}'", t)"#)]

equal to

extern crate error_chain

errors {
        InvalidToolchainName(t: String) {
            description("invalid toolchain name")
            display("invalid toolchain name: '{}'", t)


Thank you!