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

Require that errors are Send/Sync/'static.

Open withoutboats opened this issue 6 years ago • 20 comments

Currently, they are not Sync because they contain a non-Sync trait object. This is a breaking change.

The decision to make errors Send but not Sync was made in #110. We believe that decision was a mistake, because it perpetuates a !Sync restriction on all users even if their errors are, in fact, Sync. Instead, users who need errors that are !Sync should use synchronization when transforming their errors into error-chain errors.

cc @aturon

withoutboats avatar Nov 15 '17 00:11 withoutboats

I support this PR. Here are some arguments I have for supporting it.

  • io::Error is designed to wrap other errors. This is required if anyone wants to implement Read or Write and have meaningful errors. io::Error has decided that all errors that it wraps must be Sync. This means that error-chain is fighting against the standard library.
  • error-chain is recursively making everyone's errors !Sync when they don't need to be.
  • If someone wants to make their errors Sync, but one of the causal errors is !Sync because it uses error-chain, they can't implement the std::error::Error trait's cause method. The cause method returns a reference, which it can't do if the causal error is behind a Mutex.
  • If anyone rightfully has !Sync data inside of their error, it would seem pretty easy to add synchronization without affecting anything else.
  • If this isn't fixed, I would think that any library that uses error-chain should rightfully get an issue reported that their error isn't Sync when it should be. I would think it would hurt adoption of error-chain in the long run.

bvinc avatar Dec 06 '17 03:12 bvinc

cc @rust-lang-nursery/libs I'd like to merge this PR, any objections?

aturon avatar Dec 06 '17 03:12 aturon

I'm in favour of this too :+1:

KodrAus avatar Dec 06 '17 04:12 KodrAus

I have no ticky box to check off :(

Sounds great!

alexcrichton avatar Dec 06 '17 05:12 alexcrichton

If everyone is in favor, can this be merged? We'll still have to get crates that use error-chain updated to the new version, but it will definitely make interop between error-chain and failure crates much simpler.

luser avatar Feb 09 '18 16:02 luser

@withoutboats, can you merge and publish?

aturon avatar Feb 09 '18 17:02 aturon

Will do this week!

withoutboats avatar Feb 13 '18 04:02 withoutboats

@withoutboats I guess you got a bit delayed? :smile:

aidanhs avatar Aug 21 '18 15:08 aidanhs

I'd really love to see this merged.

L-as avatar Nov 03 '18 11:11 L-as

Ooo

Terkwood avatar Nov 03 '18 13:11 Terkwood

Ping @withoutboats :)

pietroalbini avatar Nov 04 '18 13:11 pietroalbini

Did you fall into a black hole? I need this. :(

Kixunil avatar Nov 26 '20 16:11 Kixunil

I don't believe we have the support required to add features to this library. We are currently only maintaining compatibility with rustc and not adding features.

AndyGauge avatar Nov 30 '20 15:11 AndyGauge

Does that mean error-chain is deprecated or you don't have the resources? Frankly, this change is so important to me that I'm willing to resolve merge conflict if someone is willing to review it and hit "Merge" button.

Kixunil avatar Nov 30 '20 16:11 Kixunil

I'm most concerned with the breaking change adversely affecting users of the library. I guess I may be taking too measured an approach.

AndyGauge avatar Nov 30 '20 22:11 AndyGauge

Ah, good point. Though the consensus was that this is wanted, so it may be worth it? It'd definitely need to be semver-breaking, so that people update at their own pace.

Kixunil avatar Nov 30 '20 22:11 Kixunil

I don't think I'm alone in my assessment that error-chain, while a useful exploration of the design space, is out of date with regards to the evolution of Rust error handling practices. If you're still actively using this crate you should consider replacing it with one of several newer crates that are actively maintained. This blog post from last year has a survey of several options, including some words on error-chain itself.

luser avatar Dec 01 '20 14:12 luser

error-chain was a pioneer in this space, and it was the work done here that created the rust primitives (that story is probably longer, more nuanced, and only influenced by error-chain). Now, it left to show why rust needed an error-handling library. Now enums and simple macros can provide the combination of error types; a library is less important.

AndyGauge avatar Dec 01 '20 15:12 AndyGauge

Right, the change would have to be breaking anyway, so might as well change the library.

Kixunil avatar Dec 01 '20 17:12 Kixunil

Made a new pull request that adds 'Sync' via a feature toggle for backwards compatibility https://github.com/rust-lang-nursery/error-chain/pull/300

john-sharratt avatar Aug 07 '21 10:08 john-sharratt