error-chain
error-chain copied to clipboard
Links and custom description / display
One thing I really dislike about error_chain compared to quick_error is the inability to add a custom description and format to foreign_link errors (and regular links as well, actually).
The docs suggest using chain_err, but this looses the type information for the cause, which is not ideal, and you have to implement From manually.
Any plans to add that functionality?
error_chain! {
foreign_links {
Io(e: ::std::io::Error) {
description("disk_io")
display("Could not read/write from disk: '{}'", e)
}
}
}
Upon investigation, you can get almost the described behaviour:
error_chain! {
errors {
Io(e: io::Error) {
description(..)
display(..)
cause(&e)
from()
}
}
}
The only thing missing is, this only gives a From implementation for io::Error to ErrorKind, and you need to implement From manually.
cause() and from() don't do anything in error-chain. You can remove them.
~~>you need to implement From manually.~~
~~Why do you need to implement manually? If you're talking about an impl for io::Error -> Error, it's unnecessary since impls for io::Error -> ErrorKind and ErrorKind -> Error are already generated.~~
Edit: Sorry, I misread that you switched to using custom links in your second post.