Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Replace error-chain #10302

Closed
niklasad1 opened this issue Feb 5, 2019 · 4 comments · Fixed by #10747
Closed

Replace error-chain #10302

niklasad1 opened this issue Feb 5, 2019 · 4 comments · Fixed by #10747
Labels
P5-sometimesoon 🌲 Issue is worth doing soon. Q5-substantial 📓 Can be fixed by a developer with decent experience.

Comments

@niklasad1
Copy link
Collaborator

error-chain is not maintained anymore and depends on Error::cause which will be deprecated in Rust 1.33.

I don't know what the best solution to this but what I can think of:

  • Manually implement it
  • Migrate to failure
@ascjones
Copy link
Contributor

In #10510 I manually implemented Error and the From impls, but used the derive_more Display derive for that boilerplate. @niklasad1 let me know what you think of this approach and we could apply to other errors.

Here's one of the regexes I used for the variants inside error_chain {} for future use:

\#\[doc = \"(.+)\"]\n\s+(.*) \{\n.*\n.*display\(\"(.*)\".*\n.*\}\n

/// $1\n\t\t#[display(fmt = "$3", _0)]\n\t\t$2,

@niklasad1
Copy link
Collaborator Author

nice work, yeah looks good to me.

could make sense to write a macro for the fn source impl:

impl error::Error for Error {
	fn source(&self) -> Option<&(error::Error + 'static)> {
		match self {
			Error::Io(e) => Some(e),
	                // more patterns
			_ => None,
		}
	}
}

@ascjones
Copy link
Contributor

At first I converted to using err-derive which has essentially just copied failure macros and allows annotating nested errors with #[cause] for this purpose.

However I decided to user the more general and popular derive_more, rather than introducing another error library.

So we could just copy that macro from there or consider adding a dependency to it. In the meantime I figured it's not that bad to implement source manually.

@niklasad1
Copy link
Collaborator Author

Ok, I see.

Let's go with a manual implementation for now and see how much extra code it will require.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P5-sometimesoon 🌲 Issue is worth doing soon. Q5-substantial 📓 Can be fixed by a developer with decent experience.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants