error-chain
error-chain copied to clipboard
Backtrace/cause tunneling through trait objects
trafficstars
You sometimes need a layer of Box<Error> in an API when e.g. making a pluginizable framework. You can currently propagate the cause chain up properly but not a backtrace.
It would be nice if ChainedError were split with a top-level trait which just extends Error and has extract_backtrace and error_chain! were updated to allow propagation of the backtrace through it. Something like
error_chain! {
errors {
Plugin(e: Box<BaseChainedError>) {
cause(e)
backtrace(e)
description("error from a plugin")
display("error from a plugin: {}", e)
}
}
}
Not sure I understand, what is BaseChainedError?
pub trait BaseChainedError: Error + 'static + Sync + Send {
fn iter(&self) -> ErrorChainIter;
fn backtrace(&self) -> Option<&Backtrace>;
}
pub trait ChainedError: BaseChainedError {
type ErrorKind;
fn from_kind(kind: Self::ErrorKind) -> Self where Self: Sized;
fn kind(&self) -> &Self::ErrorKind;
}
We can't just use ChainedError since it has the associated ErrorKind type.