-
Notifications
You must be signed in to change notification settings - Fork 13.4k
More ErrorKinds for common errnos #79965
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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0b37bb2
Redefine `ErrorKind::Other` and stop using it in std.
m-ou-se 82d3ef1
Fix copy-paste error in sys/hermit error message.
m-ou-se a0d11a4
Rename ErrorKind::Unknown to Uncategorized.
m-ou-se f092501
ErrorKind: Reformat the error string table
ijackson 5513faa
ErrorKind: Reformat the mapping table (unix)
ijackson d59d52e
ErrorKind: Reformat the mapping table (windows)
ijackson 2a38dfb
ErrorKind: Fix a spurious space
ijackson e7fb1a7
windows errors: Change type name for ERROR_SHARING_VIOLATION
ijackson 9580f33
Windows error codes: Move to a separate module
ijackson 8a4b1e4
Windows error codes: Add very very many from mingw
ijackson 655053e
Windows error codes: Add two missing ones
ijackson 1ec9454
ErrorKind: Provide many more ErrorKinds, motivated by Unix errnos
ijackson 58d0cec
ErrorKind: Windows: Fix botched rebase
ijackson 622a45d
ErrorKind: Windows: Fix tidy
ijackson c8bddf3
ErrorKind::NotSeekable: Fix reference to File::open()
ijackson f00975e
ErrorKind::FilesystemLoop: Generalise dscription
ijackson 333d42d
ErrorKind: Add missing full stops
ijackson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,12 @@ pub enum ErrorKind { | |
/// The connection was reset by the remote server. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
ConnectionReset, | ||
/// The remote host is not reachable. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
HostUnreachable, | ||
/// The network containing the remote host is not reachable. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
NetworkUnreachable, | ||
ijackson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// The connection was aborted (terminated) by the remote server. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
ConnectionAborted, | ||
|
@@ -119,6 +125,9 @@ pub enum ErrorKind { | |
/// local. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
AddrNotAvailable, | ||
/// The system's networking is down. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
NetworkDown, | ||
/// The operation failed because a pipe was closed. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
BrokenPipe, | ||
|
@@ -129,6 +138,37 @@ pub enum ErrorKind { | |
/// requested to not occur. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
WouldBlock, | ||
/// A filesystem object is, unexpectedly, not a directory. | ||
/// | ||
/// For example, a filesystem path was specified where one of the intermediate directory | ||
/// components was, in fact, a plain file. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
NotADirectory, | ||
ijackson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// The filesystem object is, unexpectedly, a directory. | ||
/// | ||
/// A directory was specified when a non-directory was expected. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
IsADirectory, | ||
ijackson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// A non-empty directory was specified where an empty directory was expected. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
DirectoryNotEmpty, | ||
ijackson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// The filesystem or storage medium is read-only, but a write operation was attempted. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
ReadOnlyFilesystem, | ||
ijackson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// Loop in the filesystem; often, too many levels of symbolic links. | ||
/// | ||
/// There was a loop (or excessively long chain) resolving a filesystem object. | ||
/// | ||
/// On Unix this is usually the result of a symbolic link loop; or, of exceeding the | ||
/// system-specific limit on the depth of symlink traversal. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
FilesystemLoop, | ||
/// Stale network file handle | ||
/// | ||
/// With some network filesystems, notably NFS, an open file (or directory) can be invalidated | ||
/// by problems with the network or server. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
StaleNetworkFileHandle, | ||
ijackson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// A parameter was incorrect. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
InvalidInput, | ||
|
@@ -158,19 +198,67 @@ 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. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
StorageFull, | ||
/// Seek on unseekable file | ||
/// | ||
/// Seeking was attempted on an open file handle which is not suitable for seeking - for | ||
/// example, on Unix, a named pipe opened with `File::open`. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
NotSeekable, | ||
/// Filesystem quota was exceeded. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
FilesystemQuotaExceeded, | ||
ijackson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// File larger than allowed or supported. | ||
/// | ||
/// This might arise from a hard limit of the underlying filesystem or file access API, or from | ||
/// an administratively imposed resource limitation. Simple disk full, and out of quota, have | ||
/// their own errors. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
FileTooLarge, | ||
ijackson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// Resource is busy. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
ResourceBusy, | ||
ijackson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// Executable file is busy. | ||
/// | ||
/// An attempt was made to write to a file which is also in use as a running program. (Not all | ||
/// operating systems detect this situation.) | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
ExecutableFileBusy, | ||
ijackson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// Deadlock (avoided) | ||
/// | ||
/// A file locking operation would result in deadlock. This situation is typically detected, if | ||
/// at all, on a best-effort basis. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
Deadlock, | ||
ijackson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// Cross-device or cross-filesystem (hard) link or rename. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
CrossesDevices, | ||
/// Too many (hard) links to the same filesystem object. | ||
/// | ||
/// The filesystem does not support making so many hardlinks to the same file. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
TooManyLinks, | ||
ijackson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// Filename too long. | ||
/// | ||
/// The limit might be from the underlying filesystem or API, or an administratively imposed | ||
/// resource limit. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
FilenameTooLong, | ||
ijackson marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. std uses |
||
/// Program argument list too long. | ||
/// | ||
/// When trying to run an external program, a system or process limit on the size of the | ||
/// arguments would have been exceeded. | ||
#[unstable(feature = "io_error_more", issue = "86442")] | ||
ArgumentListTooLong, | ||
ijackson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// This operation was interrupted. | ||
/// | ||
/// Interrupted operations can typically be retried. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
Interrupted, | ||
/// Any I/O error not part of this list. | ||
/// | ||
/// Errors that are `Other` now may move to a different or a new | ||
/// [`ErrorKind`] variant in the future. It is not recommended to match | ||
/// an error against `Other` and to expect any additional characteristics, | ||
/// e.g., a specific [`Error::raw_os_error`] return value. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
Other, | ||
|
||
/// An error returned when an operation could not be completed because an | ||
/// "end of file" was reached prematurely. | ||
|
@@ -180,6 +268,18 @@ pub enum ErrorKind { | |
/// read. | ||
#[stable(feature = "read_exact", since = "1.6.0")] | ||
UnexpectedEof, | ||
/// A custom error that does not fall under any other I/O error kind. | ||
/// | ||
/// This can be used to construct your own [`Error`]s that do not match any | ||
/// [`ErrorKind`]. | ||
/// | ||
/// This [`ErrorKind`] is not used by the standard library. | ||
/// | ||
/// Errors from the standard library that do not fall under any of the I/O | ||
/// error kinds cannot be `match`ed on, and will only match a wildcard (`_`) pattern. | ||
/// New [`ErrorKind`]s might be added in the future for some of those. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
Other, | ||
|
||
/// This operation is unsupported on this platform. | ||
/// | ||
|
@@ -191,31 +291,62 @@ pub enum ErrorKind { | |
/// to allocate enough memory. | ||
#[stable(feature = "out_of_memory_error", since = "1.54.0")] | ||
OutOfMemory, | ||
|
||
/// Any I/O error from the standard library that's not part of this list. | ||
/// | ||
/// Errors that are `Uncategorized` now may move to a different or a new | ||
/// [`ErrorKind`] variant in the future. It is not recommended to match | ||
/// an error against `Uncategorized`; use a wildcard match (`_`) instead. | ||
#[unstable(feature = "io_error_uncategorized", issue = "none")] | ||
#[doc(hidden)] | ||
Uncategorized, | ||
} | ||
|
||
impl ErrorKind { | ||
pub(crate) fn as_str(&self) -> &'static str { | ||
use ErrorKind::*; | ||
match *self { | ||
ErrorKind::NotFound => "entity not found", | ||
ErrorKind::PermissionDenied => "permission denied", | ||
ErrorKind::ConnectionRefused => "connection refused", | ||
ErrorKind::ConnectionReset => "connection reset", | ||
ErrorKind::ConnectionAborted => "connection aborted", | ||
ErrorKind::NotConnected => "not connected", | ||
ErrorKind::AddrInUse => "address in use", | ||
ErrorKind::AddrNotAvailable => "address not available", | ||
ErrorKind::BrokenPipe => "broken pipe", | ||
ErrorKind::AlreadyExists => "entity already exists", | ||
ErrorKind::WouldBlock => "operation would block", | ||
ErrorKind::InvalidInput => "invalid input parameter", | ||
ErrorKind::InvalidData => "invalid data", | ||
ErrorKind::TimedOut => "timed out", | ||
ErrorKind::WriteZero => "write zero", | ||
ErrorKind::Interrupted => "operation interrupted", | ||
ErrorKind::Other => "other os error", | ||
ErrorKind::UnexpectedEof => "unexpected end of file", | ||
ErrorKind::Unsupported => "unsupported", | ||
ErrorKind::OutOfMemory => "out of memory", | ||
AddrInUse => "address in use", | ||
AddrNotAvailable => "address not available", | ||
AlreadyExists => "entity already exists", | ||
ArgumentListTooLong => "argument list too long", | ||
BrokenPipe => "broken pipe", | ||
ResourceBusy => "resource busy", | ||
ConnectionAborted => "connection aborted", | ||
ConnectionRefused => "connection refused", | ||
ConnectionReset => "connection reset", | ||
CrossesDevices => "cross-device link or rename", | ||
Deadlock => "deadlock", | ||
DirectoryNotEmpty => "directory not empty", | ||
ExecutableFileBusy => "executable file busy", | ||
FilenameTooLong => "filename too long", | ||
FilesystemQuotaExceeded => "filesystem quota exceeded", | ||
FileTooLarge => "file too large", | ||
HostUnreachable => "host unreachable", | ||
Interrupted => "operation interrupted", | ||
InvalidData => "invalid data", | ||
InvalidInput => "invalid input parameter", | ||
IsADirectory => "is a directory", | ||
NetworkDown => "network down", | ||
NetworkUnreachable => "network unreachable", | ||
NotADirectory => "not a directory", | ||
StorageFull => "no storage space", | ||
NotConnected => "not connected", | ||
NotFound => "entity not found", | ||
Other => "other error", | ||
OutOfMemory => "out of memory", | ||
PermissionDenied => "permission denied", | ||
ReadOnlyFilesystem => "read-only filesystem or storage medium", | ||
StaleNetworkFileHandle => "stale network file handle", | ||
FilesystemLoop => "filesystem loop (e.g. symbolic link loop)", | ||
NotSeekable => "seek on unseekable file", | ||
TimedOut => "timed out", | ||
TooManyLinks => "too many links", | ||
Uncategorized => "uncategorized error", | ||
UnexpectedEof => "unexpected end of file", | ||
Unsupported => "unsupported", | ||
WouldBlock => "operation would block", | ||
WriteZero => "write zero", | ||
} | ||
} | ||
} | ||
|
@@ -538,7 +669,7 @@ impl Error { | |
/// } | ||
/// | ||
/// fn main() { | ||
/// // Will print "Other". | ||
/// // Will print "Uncategorized". | ||
/// print_error(Error::last_os_error()); | ||
/// // Will print "AddrInUse". | ||
/// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.