Skip to content

std: IntoInnerError into_parts, NoStorageSpace #78689

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions library/std/src/io/buffered/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@ impl<W> IntoInnerError<W> {
pub fn into_inner(self) -> W {
self.0
}

#[doc(test(attr(cfg(os = "linux"))))]
/// Consumes the [`IntoInnerError`] and returns the error which caused the call to
/// [`BufWriter::into_inner()`] to fail, and the underlying writer.
///
/// This can be used to simply obtain ownership of the underlying error; it can also be used for
/// advanced error recovery.
///
/// # Example (requires `/dev/full`, which is available on Linux)
/// ```
/// use std::io::{BufWriter, ErrorKind, Write};
/// use std::fs::File;
///
/// let mut stream = BufWriter::new(File::create("/dev/full").unwrap());
/// write!(stream, "this cannot be actually written").unwrap();
/// let into_inner_err = stream.into_inner().expect_err("now we discover the ENOSPC");
/// let (err, _writer) = into_inner_err.into_parts();
/// assert_eq!(err.kind(), ErrorKind::NoStorageSpace);
/// ```
#[stable(feature = "std_io_into_inner_error_into_inner_parts", since = "1.51.0")]
pub fn into_parts(self) -> (Error, W) {
(self.1, self.0)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
6 changes: 6 additions & 0 deletions library/std/src/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ pub enum ErrorKind {
/// [`Ok(0)`]: Ok
#[stable(feature = "rust1", since = "1.0.0")]
WriteZero,
/// 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.

NoStorageSpace,
/// This operation was interrupted.
///
/// Interrupted operations can typically be retried.
Expand Down Expand Up @@ -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.

ErrorKind::Other => "other os error",
ErrorKind::UnexpectedEof => "unexpected end of file",
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
libc::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
libc::EADDRINUSE => ErrorKind::AddrInUse,
libc::ENOENT => ErrorKind::NotFound,
libc::ENOSPC => ErrorKind::NoStorageSpace,
libc::EINTR => ErrorKind::Interrupted,
libc::EINVAL => ErrorKind::InvalidInput,
libc::ETIMEDOUT => ErrorKind::TimedOut,
Expand Down