ErrorKind: Provide many more ErrorKinds, motivated by Unix errnos
Rationale for the mappings etc. is extensively discussed in the MR https://github.com/rust-lang/rust/pull/79965 Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
This commit is contained in:
parent
655053ed91
commit
1ec9454403
@ -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,
|
||||
/// 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,
|
||||
/// 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,
|
||||
/// A non-empty directory was specified where an empty directory was expected.
|
||||
#[unstable(feature = "io_error_more", issue = "86442")]
|
||||
DirectoryNotEmpty,
|
||||
/// The filesystem or storage medium is read-only, but a write operation was attempted.
|
||||
#[unstable(feature = "io_error_more", issue = "86442")]
|
||||
ReadOnlyFilesystem,
|
||||
/// 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,
|
||||
/// A parameter was incorrect.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
InvalidInput,
|
||||
@ -158,6 +198,62 @@ 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::new`.
|
||||
#[unstable(feature = "io_error_more", issue = "86442")]
|
||||
NotSeekable,
|
||||
/// Filesystem quota was exceeded.
|
||||
#[unstable(feature = "io_error_more", issue = "86442")]
|
||||
FilesystemQuotaExceeded,
|
||||
/// 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,
|
||||
/// Resource is busy.
|
||||
#[unstable(feature = "io_error_more", issue = "86442")]
|
||||
ResourceBusy,
|
||||
/// 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,
|
||||
/// 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,
|
||||
/// 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,
|
||||
/// 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,
|
||||
/// 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,
|
||||
/// This operation was interrupted.
|
||||
///
|
||||
/// Interrupted operations can typically be retried.
|
||||
@ -213,19 +309,39 @@ impl ErrorKind {
|
||||
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",
|
||||
|
@ -135,20 +135,40 @@ pub use libc::signal;
|
||||
pub fn decode_error_kind(errno: i32) -> ErrorKind {
|
||||
use ErrorKind::*;
|
||||
match errno as libc::c_int {
|
||||
libc::E2BIG => ArgumentListTooLong,
|
||||
libc::EADDRINUSE => AddrInUse,
|
||||
libc::EADDRNOTAVAIL => AddrNotAvailable,
|
||||
libc::EBUSY => ResourceBusy,
|
||||
libc::ECONNABORTED => ConnectionAborted,
|
||||
libc::ECONNREFUSED => ConnectionRefused,
|
||||
libc::ECONNRESET => ConnectionReset,
|
||||
libc::EDEADLK => Deadlock,
|
||||
libc::EDQUOT => FilesystemQuotaExceeded,
|
||||
libc::EEXIST => AlreadyExists,
|
||||
libc::EFBIG => FileTooLarge,
|
||||
libc::EHOSTUNREACH => HostUnreachable,
|
||||
libc::EINTR => Interrupted,
|
||||
libc::EINVAL => InvalidInput,
|
||||
libc::EISDIR => IsADirectory,
|
||||
libc::ELOOP => FilesystemLoop,
|
||||
libc::ENOENT => NotFound,
|
||||
libc::ENOMEM => OutOfMemory,
|
||||
libc::ENOSPC => StorageFull,
|
||||
libc::ENOSYS => Unsupported,
|
||||
libc::EMLINK => TooManyLinks,
|
||||
libc::ENAMETOOLONG => FilenameTooLong,
|
||||
libc::ENETDOWN => NetworkDown,
|
||||
libc::ENETUNREACH => NetworkUnreachable,
|
||||
libc::ENOTCONN => NotConnected,
|
||||
libc::ENOTDIR => NotADirectory,
|
||||
libc::ENOTEMPTY => DirectoryNotEmpty,
|
||||
libc::EPIPE => BrokenPipe,
|
||||
libc::EROFS => ReadOnlyFilesystem,
|
||||
libc::ESPIPE => NotSeekable,
|
||||
libc::ESTALE => StaleNetworkFileHandle,
|
||||
libc::ETIMEDOUT => TimedOut,
|
||||
libc::ETXTBSY => ExecutableFileBusy,
|
||||
libc::EXDEV => CrossesDevices,
|
||||
|
||||
libc::EACCES | libc::EPERM => PermissionDenied,
|
||||
|
||||
|
@ -90,6 +90,24 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
|
||||
| c::ERROR_RUNLEVEL_SWITCH_TIMEOUT
|
||||
| c::ERROR_RUNLEVEL_SWITCH_AGENT_TIMEOUT => return TimedOut,
|
||||
c::ERROR_CALL_NOT_IMPLEMENTED => return Unsupported,
|
||||
| c::ERROR_RUNLEVEL_SWITCH_AGENT_TIMEOUT => return TimedOut,
|
||||
c::ERROR_CALL_NOT_IMPLEMENTED => return Unsupported,
|
||||
c::ERROR_HOST_UNREACHABLE => return HostUnreachable,
|
||||
c::ERROR_NETWORK_UNREACHABLE => return NetworkUnreachable,
|
||||
c::ERROR_DIRECTORY => return NotADirectory,
|
||||
c::ERROR_DIRECTORY_NOT_SUPPORTED => return IsADirectory,
|
||||
c::ERROR_DIR_NOT_EMPTY => return DirectoryNotEmpty,
|
||||
c::ERROR_WRITE_PROTECT => return ReadOnlyFilesystem,
|
||||
c::ERROR_DISK_FULL
|
||||
| c::ERROR_HANDLE_DISK_FULL => return StorageFull,
|
||||
c::ERROR_SEEK_ON_DEVICE => return NotSeekable,
|
||||
c::ERROR_DISK_QUOTA_EXCEEDED => return FilesystemQuotaExceeded,
|
||||
c::ERROR_FILE_TOO_LARGE => return FileTooLarge,
|
||||
c::ERROR_BUSY => return ResourceBusy,
|
||||
c::ERROR_POSSIBLE_DEADLOCK => return Deadlock,
|
||||
c::ERROR_NOT_SAME_DEVICE => return CrossesDevices,
|
||||
c::ERROR_TOO_MANY_LINKS => return TooManyLinks,
|
||||
c::ERROR_FILENAME_EXCED_RANGE => return FilenameTooLong,
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@ -104,6 +122,9 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
|
||||
c::WSAENOTCONN => NotConnected,
|
||||
c::WSAEWOULDBLOCK => WouldBlock,
|
||||
c::WSAETIMEDOUT => TimedOut,
|
||||
c::WSAEHOSTUNREACH => HostUnreachable,
|
||||
c::WSAENETDOWN => NetworkDown,
|
||||
c::WSAENETUNREACH => NetworkUnreachable,
|
||||
|
||||
_ => Uncategorized,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user