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

Clarify Error::last_os_error can be weird #106964

Merged

Conversation

workingjubilee
Copy link
Member

@workingjubilee workingjubilee commented Jan 17, 2023

Fundamentally, querying the OS for error codes is a process that is deeply subject to the whims of chance and fortune. We can account for OS, but not for every combination of platform APIs. A compiled binary may not recognize new errors introduced years later. We should clarify a few especially odd situations, and what they mean: We can effectively promise nothing... if you ask for Rust to decode errors where none have occurred.

This allows removing mention of ErrorKind::Uncategorized.
That error variant is hidden deliberately, so we should not explicitly mention it.

This fixes #106937.

Since you had an opinion also: Does this solution seem acceptable?
r? @ChrisDenton

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 17, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jan 17, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@ChrisDenton
Copy link
Member

Hm, this does seem to adequately address the issue but I do think it'd be useful for the kind() docs to have some mention of what happens with OS errors (i.e. with last_os_error and from_raw_os_error their kind is automatically determined based on the OS error code). The from_raw_os_error has a relevant example so maybe it's enough to link to that method's docs.

Fundamentally, querying the OS for error codes is a process
that is deeply subject to the whims of chance and fortune.
We can account for OS, but not for every combination of platform APIs.
A compiled binary may not recognize new errors introduced years later.
We should clarify a few especially odd situations, and what they mean:
We can effectively promise nothing.

This allows removing mention of ErrorKind::Uncategorized.
That error variant is hidden quite deliberately, so we
should not explicitly mention it.
@workingjubilee workingjubilee force-pushed the crouching-ioerror-hidden-documentation branch from efda533 to 2d927cc Compare January 17, 2023 04:58
@workingjubilee workingjubilee changed the title Remove mention of ErrorKind::Uncategorized Clarify Error::last_os_error can be weird Jan 17, 2023
@workingjubilee
Copy link
Member Author

I tried an alternative tack of explaining that if you ask Rust to decode an error where none has actually occurred, it may not make sense. It may have even been set to random values by a truly spiteful OS. We're just a standard library, and are not necessarily capable of suggesting you ask a different question instead.

@ChrisDenton
Copy link
Member

To be honest, I think the initial PR was more in the right direction than this alternative tack. There's no need for kind() to get into the nuances of last_os_error(). The important points are, I think, that kind() will either return the io::Kind that was set in a custom io::Error or else return an io::Kind that's inferred from an OS error code.

@workingjubilee
Copy link
Member Author

More like this, then?

@workingjubilee workingjubilee force-pushed the crouching-ioerror-hidden-documentation branch from bcc9103 to 0f32fd8 Compare March 17, 2023 21:26
@ChrisDenton
Copy link
Member

Yeah. I'll admit to still being slightly uncomfortable with the example but I think this is a definite improvement. So...

@bors r+

@bors
Copy link
Contributor

bors commented Mar 22, 2023

📌 Commit 0f32fd8 has been approved by ChrisDenton

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 22, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Mar 22, 2023
…idden-documentation, r=ChrisDenton

Clarify `Error::last_os_error` can be weird

Fundamentally, querying the OS for error codes is a process that is deeply subject to the whims of chance and fortune. We can account for OS, but not for every combination of platform APIs. A compiled binary may not recognize new errors introduced years later. We should clarify a few especially odd situations, and what they mean: We can effectively promise nothing... if you ask for Rust to decode errors where none have occurred.

This allows removing mention of ErrorKind::Uncategorized.
That error variant is hidden deliberately, so we should not explicitly mention it.

This fixes rust-lang#106937.

Since you had an opinion also: Does this solution seem acceptable?
r? `@ChrisDenton`
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 23, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#106964 (Clarify `Error::last_os_error` can be weird)
 - rust-lang#107718 (Add `-Z time-passes-format` to allow specifying a JSON output for `-Z time-passes`)
 - rust-lang#107880 (Lint ambiguous glob re-exports)
 - rust-lang#108549 (Remove issue number for `link_cfg`)
 - rust-lang#108588 (Fix the ffi_unwind_calls lint documentation)
 - rust-lang#109231 (Add `try_canonicalize` to `rustc_fs_util` and use it over `fs::canonicalize`)
 - rust-lang#109472 (Add parentheses properly for method calls)
 - rust-lang#109487 (Move useless_anynous_reexport lint into unused_imports)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit aeabe34 into rust-lang:master Mar 23, 2023
@rustbot rustbot added this to the 1.70.0 milestone Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unclear example in io::Error
5 participants