Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backtrace/cause tunneling through trait objects #111

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

Comments

Projects
None yet
2 participants
@sfackler
Copy link
Member

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

This comment has been minimized.

Copy link
Collaborator

Yamakaky commented Jan 4, 2017

Not sure I understand, what is BaseChainedError?

@sfackler

This comment has been minimized.

Copy link
Member 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 join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.