-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
rename Error::iter_chain() and remove Error::iter_sources() #65557
Conversation
r? @kennytm (rust_highfive has picked a reviewer for you, use r? to override) |
I'd like to suggest to entirely remove |
It's the other way round, but yes, I agree that we might only want to have one. |
Oh, but then the suggested names are somehow counter-intuitive, because |
Am I really confused or is everyone else? Path::ancestors includes the original, while Error::ancestors does not. I'd honestly prefer just .sources() as source is already the terminology we use nowadays for the underlying error. We already deprecated .cause(), so introducing yet another term for it is just confusing as can be seen in this thread. |
1ec0312
to
71599e3
Compare
So, it seems, that even Path::ancestors() includes itself. So, to avoid confusion and simplify it more, I reduced PR #65557 to only have Rationale:
|
71599e3
to
323f6a4
Compare
I think in the majority of the cases you only want the sources, so I'd say this is definitely catering more towards an edge case scenario where you would want the current Error as well, having a negative impact on the usual use case. But I definitely agree that it simplifies the implementation and reduces the problem to just a single iterator. |
I disagree. E.g. when displaying errors, I am usually interested in the actual error and all the causes. Thus, an iterator that does not include One more data point about the naming: https://docs.rs/anyhow/1.0.17/anyhow/struct.Error.html#method.chain |
I think we should go with Naming APIs "in honor" of old libraries does not seem consistent with std's usual UX, which doesn't make reference to other crates or Rust's history, and doesn't expect the user to know anything about that. The use of "chained" here doesn't seem clear without that context. I'm +1 on the shape of the API proposed here. If you're comfortable with the name sources @haraldh, I'd r+. |
.sources() including self, instead of just the sources is even more confusing imo. That's not what the current .iter_sources() does and it's the reason why there's a separate .iter_chain(). |
exactly this was also my thinking!! |
After thinking once again about this, I believe, the best option is Rationale:
Although this is certainly a good approach, I think, we haven't followed it all the time, e.g. when integrating the futures crate into the standard library. But, fair enough, my wording ("in honor of I think, the question to ask is "What does the iterator represent?". My answer is: the causal chain of errors leading to |
Rename * Error::iter_chain() -> Error::chain() * ErrorIter -> Chain Removed * Error::iter_sources() according to rust-lang#58520 Rationale: 1. Such iterators are helpful. They should better be stabilized sooner than later. 2. self should be included. It is easy to .skip(1) it. Not including self is harmful because it is harder to add self to the iterator than to remove it. 3. The chosen name should be telling and reflect the fact that self is included. `.chain()` was chosen because the iterator iterates over the chain of errors that is somehow included in self. 4. The resulting iterator is named `Chain` because the `error::Chain` is what we want to have.
323f6a4
to
7b9d50d
Compare
yeah, I like |
@withoutboats or do you insist on having |
A separate method and iterator for sources excluding |
Ping from triage |
r? @sfackler |
want me to tackle #58520 (comment) ? |
rename Error::iter_chain() and remove Error::iter_sources() ~~Rename~~ * ~~Error::iter_chain() -> Error::chained()~~ * ~~Error::iter_sources() -> Error::ancestors()~~ * ~~ErrorIter -> Chained and Ancestors~~ according to rust-lang#58520 (comment) Tracker: rust-lang#58520 Edit: Rename * Error::iter_chain() -> Error::chained() * ErrorIter -> Chain So, it seems, that even Path::ancestors() includes itself. So, to avoid confusion and simplify it more, I reduced PR rust-lang#65557 to only have `chained` and `Chain`. Rationale: 1. Such iterators are helpful. They should better be stabilized sooner than later. 1. self should be included. It is easy to .skip(1) it. Not including self is harmful because it is harder to add self to the iterator than to remove it. 1. The chosen name should be telling and reflect the fact that self is included. `.chained()` was chosen in honor of error-chain and because the iterator iterates over the chain of errors that is somehow included in self. 1. The resulting iterator is named `Chain` because the `error::Chain` is what we want to have.
⌛ Testing commit 7b9d50d with merge 1eefd5f6621fb7dbbe0e04df6070bc0a608bb6fe... |
@bors retry rolled up |
⌛ Testing commit 7b9d50d with merge 182ce0c4e2fbe7cf5f95e1871683de94f1d45497... |
rename Error::iter_chain() and remove Error::iter_sources() ~~Rename~~ * ~~Error::iter_chain() -> Error::chained()~~ * ~~Error::iter_sources() -> Error::ancestors()~~ * ~~ErrorIter -> Chained and Ancestors~~ according to rust-lang#58520 (comment) Tracker: rust-lang#58520 Edit: Rename * Error::iter_chain() -> Error::chained() * ErrorIter -> Chain So, it seems, that even Path::ancestors() includes itself. So, to avoid confusion and simplify it more, I reduced PR rust-lang#65557 to only have `chained` and `Chain`. Rationale: 1. Such iterators are helpful. They should better be stabilized sooner than later. 1. self should be included. It is easy to .skip(1) it. Not including self is harmful because it is harder to add self to the iterator than to remove it. 1. The chosen name should be telling and reflect the fact that self is included. `.chained()` was chosen in honor of error-chain and because the iterator iterates over the chain of errors that is somehow included in self. 1. The resulting iterator is named `Chain` because the `error::Chain` is what we want to have.
@bors retry rolled up |
rename Error::iter_chain() and remove Error::iter_sources() ~~Rename~~ * ~~Error::iter_chain() -> Error::chained()~~ * ~~Error::iter_sources() -> Error::ancestors()~~ * ~~ErrorIter -> Chained and Ancestors~~ according to rust-lang#58520 (comment) Tracker: rust-lang#58520 Edit: Rename * Error::iter_chain() -> Error::chained() * ErrorIter -> Chain So, it seems, that even Path::ancestors() includes itself. So, to avoid confusion and simplify it more, I reduced PR rust-lang#65557 to only have `chained` and `Chain`. Rationale: 1. Such iterators are helpful. They should better be stabilized sooner than later. 1. self should be included. It is easy to .skip(1) it. Not including self is harmful because it is harder to add self to the iterator than to remove it. 1. The chosen name should be telling and reflect the fact that self is included. `.chained()` was chosen in honor of error-chain and because the iterator iterates over the chain of errors that is somehow included in self. 1. The resulting iterator is named `Chain` because the `error::Chain` is what we want to have.
⌛ Testing commit 7b9d50d with merge 6f6f08cd026987e2f5961d1df141ef771b370956... |
rename Error::iter_chain() and remove Error::iter_sources() ~~Rename~~ * ~~Error::iter_chain() -> Error::chained()~~ * ~~Error::iter_sources() -> Error::ancestors()~~ * ~~ErrorIter -> Chained and Ancestors~~ according to rust-lang#58520 (comment) Tracker: rust-lang#58520 Edit: Rename * Error::iter_chain() -> Error::chained() * ErrorIter -> Chain So, it seems, that even Path::ancestors() includes itself. So, to avoid confusion and simplify it more, I reduced PR rust-lang#65557 to only have `chained` and `Chain`. Rationale: 1. Such iterators are helpful. They should better be stabilized sooner than later. 1. self should be included. It is easy to .skip(1) it. Not including self is harmful because it is harder to add self to the iterator than to remove it. 1. The chosen name should be telling and reflect the fact that self is included. `.chained()` was chosen in honor of error-chain and because the iterator iterates over the chain of errors that is somehow included in self. 1. The resulting iterator is named `Chain` because the `error::Chain` is what we want to have.
@bors retry rolled up |
Rollup of 12 pull requests Successful merges: - #65557 (rename Error::iter_chain() and remove Error::iter_sources()) - #66013 (Avoid hashing the key twice in `get_query()`.) - #66306 (Remove cannot mutate statics in initializer of another static error) - #66338 (Update mdbook.) - #66388 (Do not ICE on recovery from unmet associated type bound obligation) - #66390 (Fix ICE when trying to suggest `Type<>` instead of `Type()`) - #66391 (Do not ICE in `if` without `else` in `async fn`) - #66394 (Fix two OOM issues related to `ConstProp`) - #66398 (Remove some stack frames from `.async` calls) - #66410 (miri: helper methods for max values of machine's usize/isize) - #66418 (Link to tracking issue in HIR const-check error code description) - #66419 (Don't warn labels beginning with `_` on unused_labels lint) Failed merges: r? @ghost
⌛ Testing commit 7b9d50d with merge 3f3b7ba169b20c03f9e014895a87f142f9e4e79c... |
rename Error::iter_chain() and remove Error::iter_sources() ~~Rename~~ * ~~Error::iter_chain() -> Error::chained()~~ * ~~Error::iter_sources() -> Error::ancestors()~~ * ~~ErrorIter -> Chained and Ancestors~~ according to rust-lang#58520 (comment) Tracker: rust-lang#58520 Edit: Rename * Error::iter_chain() -> Error::chained() * ErrorIter -> Chain So, it seems, that even Path::ancestors() includes itself. So, to avoid confusion and simplify it more, I reduced PR rust-lang#65557 to only have `chained` and `Chain`. Rationale: 1. Such iterators are helpful. They should better be stabilized sooner than later. 1. self should be included. It is easy to .skip(1) it. Not including self is harmful because it is harder to add self to the iterator than to remove it. 1. The chosen name should be telling and reflect the fact that self is included. `.chained()` was chosen in honor of error-chain and because the iterator iterates over the chain of errors that is somehow included in self. 1. The resulting iterator is named `Chain` because the `error::Chain` is what we want to have.
@bors retry rolled up |
Rollup of 12 pull requests Successful merges: - #65557 (rename Error::iter_chain() and remove Error::iter_sources()) - #66013 (Avoid hashing the key twice in `get_query()`.) - #66306 (Remove cannot mutate statics in initializer of another static error) - #66338 (Update mdbook.) - #66388 (Do not ICE on recovery from unmet associated type bound obligation) - #66390 (Fix ICE when trying to suggest `Type<>` instead of `Type()`) - #66391 (Do not ICE in `if` without `else` in `async fn`) - #66398 (Remove some stack frames from `.async` calls) - #66410 (miri: helper methods for max values of machine's usize/isize) - #66418 (Link to tracking issue in HIR const-check error code description) - #66419 (Don't warn labels beginning with `_` on unused_labels lint) - #66428 (Cleanup unused function) Failed merges: r? @ghost
RenameError::iter_chain() -> Error::chained()Error::iter_sources() -> Error::ancestors()ErrorIter -> Chained and Ancestorsaccording to
#58520 (comment)
Tracker:
#58520
Edit:
Rename
So, it seems, that even Path::ancestors() includes itself. So, to avoid confusion and simplify it more, I reduced PR #65557 to only have
chained
andChain
.Rationale:
.chained()
was chosen in honor of error-chain and because the iterator iterates over the chain of errors that is somehow included in self.Chain
because theerror::Chain
is what we want to have.