Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

std: IntoInnerError into_parts, NoStorageSpace #78689

Closed

Conversation

ijackson
Copy link
Contributor

@ijackson ijackson commented Nov 2, 2020

Hi. I was doing something with std and BufWriterr and I discovered that after getting an IntoInnerError I wasn't able to get an owned copy of the contained io::Error. That seemed wrong, so I set about making an MR to fix it. That is the 2nd commit here.

While doing this I wanted to write a doctest. I wasn't able to think of a reliable portable way of provoking a convenient io error but on Linux at least we have /dev/full so I used that. I think I have marked the doctest with the appropriate attribute. I guess I'll see what the CI says.

But the doctest wants to say something about the actual error, and unaccountably ErrorKind lacks a variant corresponding to ENOSPC. Given that the docs say that existing errors of kind Other may change into specific errors, I thought this was not a breaking change.

I have made both of these things insta-stable. That will definitely need an fcp at least, and also this is my first attempt to (1) do a platform-specific doctest and (2) provide an insta-stable method on something in std, so it will need some review from appropriate people!

Additionally, since I know nothing about Windows I have not added anything to do with ErrorKind::NoStorageSpace there. I don't know if this ought to be a blocker. My git grep also found some stuff to do with vxworks; I don't know if that has ENOSPC.

Thanks for your attention.

The lack of this is surprising.  Also I am about to want it for an
example.

This has to be insta-stable because we can't sensibly have a different
set of ErrorKinds depending on a std feature flag.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
In particular, IntoIneerError only currently provides .error() which
returns a reference, not an owned value.  This is not helpful and
means that a caller of BufWriter::into_inner cannot acquire an owned
io::Error which seems quite wrong.

I have made this insta-stable because I think it ought to be very
uncontroversial.  It doesn't involve promising new facts about the
underlying implementation; it just gives a better access to the facts
which are already implied.  The lack of the usual `into_parts` seems
simply an oversight.

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

r? @m-ou-se

(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 2, 2020
@jyn514 jyn514 added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Nov 2, 2020
Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect this to be two different PRs, especially since both of these are insta-stable. That said, I'm not on libs, so the team may feel differently.

/// The underlying storage (typically, a filesystem) is full.
///
/// This does not include out of quota errors.
#[stable(feature = "io_error_no_storage_space", since = "1.51.0")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.47 is stable and 1.49 is the current nightly.

Suggested change
#[stable(feature = "io_error_no_storage_space", since = "1.51.0")]
#[stable(feature = "io_error_no_storage_space", since = "1.49.0")]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I'm a bit pessimistic about when this might go in but if it seems right in principle I will change it obviously.

@@ -199,6 +204,7 @@ impl ErrorKind {
ErrorKind::TimedOut => "timed out",
ErrorKind::WriteZero => "write zero",
ErrorKind::Interrupted => "operation interrupted",
ErrorKind::NoStorageSpace => "no storage space",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ errno ENOSPC
ENOSPC 28 No space left on device
Suggested change
ErrorKind::NoStorageSpace => "no storage space",
ErrorKind::NoStorageSpace => "no space left on device",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I'm happy to change the message to be identical to the traditional Unix one if that seems better. But most of the existing messages do not mirror the traditional Unix ones.

@jyn514 jyn514 added A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` needs-fcp This change is insta-stable, so needs a completed FCP to proceed. labels Nov 2, 2020
@ijackson
Copy link
Contributor Author

ijackson commented Nov 2, 2020

I would expect this to be two different PRs, especially since both of these are insta-stable. That said, I'm not on libs, so the team may feel differently.

If it would be two PRs, one of them would depend on the other. I don't know what the usual way is to handle that situation in rust-lang. I'm happy to go with whatever the usual approach is, obviously.

Thanks for the review, anyway. Let's see what the libs folk think.

@m-ou-se
Copy link
Member

m-ou-se commented Nov 3, 2020

If you use a local buffer instead of a File, you can make the example cross platform:

	let mut not_enough_space = [0u8; 10];
	let mut stream = BufWriter::new(not_enough_space.as_mut());
	write!(stream, "this does not fit entirely in the array").unwrap();
        ...

So then you don't need ErrorKind::NoStorageSpace here.

(If you think ErrorKind::NoStorageSpace is useful by itself, please open a separate PR for that.)

@ijackson
Copy link
Contributor Author

ijackson commented Nov 3, 2020 via email

@crlf0710
Copy link
Member

@ijackson Ping from triage! Any updates on this?

@crlf0710 crlf0710 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 Nov 20, 2020
@ijackson
Copy link
Contributor Author

ijackson commented Dec 3, 2020

This MR will be confusing If I reuse it for either of the two halves. So I am going to close it and redo this with two separate MRs for the two halves.

Thanks.

@ijackson ijackson closed this Dec 3, 2020
@ijackson ijackson deleted the wip.intoinnerintoinnererror branch December 3, 2020 01:03
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 4, 2020
…-ou-se

Provide IntoInnerError::into_parts

Hi.  This is an updated version of the IntoInnerError bits of my previous portmanteau MR rust-lang#78689.  Thanks to `@jyn514` and `@m-ou-se` for helpful comments there.

I have made this insta-stable since it seems like it will probably be uncontroversial, but that is definitely something that someone from the libs API team should be aware of and explicitly consider.

I included a tangentially-related commit providing documentation of the buffer full behaviiour of `&mut [u8] as Write`; the behaviour I am documenting is relied on by the doctest for `into_parts`.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` needs-fcp This change is insta-stable, so needs a completed FCP to proceed. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants