derive-error-chain icon indicating copy to clipboard operation
derive-error-chain copied to clipboard

Replace `error_chain!`

Open Yamakaky opened this issue 7 years ago • 6 comments

With macros 1.1 on stable, do you think your crate could replace the upstream error_chain?

Yamakaky avatar Feb 06 '17 16:02 Yamakaky

What I said here is still mostly true. Compared to the error_chain! macro, here the user needs to declare an enum, remember to mark it pub, remember to derive Debug, and remember to provide a Msg(String) member. Then for each variant, instead of nice function syntax for display and description they have to make a separate function or embed it in a string.

You can see an example at https://github.com/Arnavion/fac-rs/blob/2a8f67bb/factorio-mods-local/src/error.rs That repo is probably the only bunch of crates that use it. I've not heard of anyone else using it nor received any feedback.

The error_chain! macro has its place for convenience. I would never go as far as replacing it entirely. At best this can function as a (currently experimental) alternative.

Arnavion avatar Feb 06 '17 18:02 Arnavion

I'm thinking: can't we modify error_chain! to use derive-error-chain in the background? That way we would have more code in common.

Yamakaky avatar Feb 06 '17 19:02 Yamakaky

It might be possible.

Arnavion avatar Feb 06 '17 19:02 Arnavion

What do you think @brson?

Yamakaky avatar Feb 06 '17 19:02 Yamakaky

(I should clarify that I think it might be possible, not that it's a good idea. It seems unnecessarily roundabout for a regular macro to generate input for another proc macro.)

Arnavion avatar Feb 06 '17 20:02 Arnavion

An update to my earlier sentiments, based on the last few months:

That repo [Arnavion/fac-rs] is probably the only bunch of crates that use it. I've not heard of anyone else using it nor received any feedback.

This is no longer true since atleast dotenv uses it, and one user has submitted a PR to add support for generic errorkinds.

The error_chain! macro has its place for convenience. I would never go as far as replacing it entirely.

However upstream is considering replacing it entirely. https://github.com/rust-lang-nursery/error-chain/issues/170

At best this can function as a (currently experimental) alternative.

I don't consider this crate experimental any more.

Arnavion avatar Aug 07 '17 23:08 Arnavion