Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Backtrace/cause tunneling through trait objects #111

Open
sfackler opened this issue Jan 4, 2017 · 2 comments
Open

Backtrace/cause tunneling through trait objects #111

sfackler opened this issue Jan 4, 2017 · 2 comments

Comments

@sfackler
Copy link
Contributor

sfackler commented Jan 4, 2017

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)
        }
    }
}
@Yamakaky
Copy link
Contributor

Yamakaky commented Jan 4, 2017

Not sure I understand, what is BaseChainedError?

@sfackler
Copy link
Contributor Author

sfackler commented Jan 4, 2017

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.

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

No branches or pull requests

2 participants