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

io::ErrorKind: Discuss matching #90706

Closed
wants to merge 1 commit into from

Conversation

ijackson
Copy link
Contributor

@ijackson ijackson commented Nov 8, 2021

Here I add a cross-reference to a blog post (one of my own). I have no idea if that is allowed. (FWIW the URL is stable and I don't expect Dreamwidth do go away.)

I did it like this because this extensive discussion doesn't readily fit into the stdlib docs. I'm prepared for the possiblity that the suggestion to c&p, or the external reference, might be controversial...

Closes #89175

Closes rust-lang#89175

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 8, 2021
@Mark-Simulacrum
Copy link
Member

I don't think we should link to an external blog post here, but I do think including those longer-form docs somewhere makes sense. Given that it's at least generally accepted already, maybe a good strategy would be to propose an RFC for T-libs, which we can then link to? I imagine getting that RFC into FCP would not take too long.

r? @m-ou-se since the question here is basically where to best put these docs

@joshtriplett
Copy link
Member

Agreed regarding external posts.

For the time being, I'd be happy to merge this with the last line removed, or replaced with a summary.

I do think the suggestion to copy-paste (for the case of exhaustive tests) is reasonable here.

@ijackson
Copy link
Contributor Author

For the time being, I'd be happy to merge this with the last line removed, or replaced with a summary.

I do think the suggestion to copy-paste (for the case of exhaustive tests) is reasonable here.

The difficulty is that without a longer explanation (I don't think a summary will do) the suggestion to c&p is highly unusual, and runs very counter to usual advice. Without a full explanation I doubt many readers will follow the advice; they might dismiss the doc as written by idiots or lunatics.

I like the suggestion of putting this into an RFC, albeit after the decision has already been taken. My blog post has many of the elements of such an RFC in it already.

@joshtriplett
Copy link
Member

@ijackson The explanation in your post is four paragraphs; I don't think that'd be unreasonable, and it may also be possible to reduce further (as your post was optimizing for both a less-familiar audience and an expectation of potential incredulity).

Also, on balance, I don't think people are in the habit of assuming that the standard library documentation's recommendations are wildly unreasonable; on the contrary, we usually have the problem of people taking them too seriously. (This is, for instance, one reason why we don't tend to recommend specific third-party crates, because that recommendation carries too much weight.)

Borrowing heavily from your post, here's a summary that should be sufficiently clear and self-contained:

In comprehensive and thorough tests that want to verify that a test doesn't return any known incorrect error kind, you may want to cut-and-paste the current list of errors from here into your test code. This seems counterintuitive, but it will make your tests more robust. In particular, if you want to verify that your code does produce an unrecognized error kind, the robust solution is to check for all the recognized error kinds and fail in those cases.

You don't want to test specifically that an error is not recognized by the version of the Rust standard library currently in use, because Rust might start recognizing more errors; when the test is compiled and run later, perhaps years later, the error in this test case might indeed be categorized. You want to test that the error is not any of the error kinds which existed when the test was written; thus, you want to copy-paste the list of known error kinds.

Copy-pasting will seem wrong, because the list in your code and in Rust can get out of step. But when they do get out of step you want your version, not the standard library's.

You probably only want to maintain one copy of this list, so put it somewhere central in your codebase's test support machinery. Periodically, you can update the list deliberately - and fix any resulting test failures.

@apiraino apiraino added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Nov 11, 2021
@JohnCSimon
Copy link
Member

Triage: @ijackson - returning to author
@rustbot label: +S-waiting-on-author -S-waiting-on-review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 5, 2021
@Mark-Simulacrum
Copy link
Member

One thought I additionally had just now: it may be reasonable for us to either provide a copyable snippet that is updated when variants are added (so that it's easy to get started, and if you already read/trust the documentation, can just directly copy).

We could also consider exposing a function which asserts on behalf of the user, with a version parameter. But that would be significantly "new ground" (exposing versions, etc), though might allow for better error messages than would otherwise be possible (e.g., indicating which version the new variant was added in).

@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 23, 2022
@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 12, 2022
@JohnCSimon
Copy link
Member

Ping from triage:
@ijackson Can you address the comments from the reviewers and post your status on this PR?

@Dylan-DPC
Copy link
Member

reworked in #94273

@Dylan-DPC Dylan-DPC closed this Feb 23, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

io::ErrorKind should suggest c&p current list of kinds into test cases
9 participants