Skip to content

Commit 1ec9454

Browse files
committed
ErrorKind: Provide many more ErrorKinds, motivated by Unix errnos
Rationale for the mappings etc. is extensively discussed in the MR #79965 Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
1 parent 655053e commit 1ec9454

File tree

3 files changed

+157
-0
lines changed

3 files changed

+157
-0
lines changed

library/std/src/io/error.rs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ pub enum ErrorKind {
105105
/// The connection was reset by the remote server.
106106
#[stable(feature = "rust1", since = "1.0.0")]
107107
ConnectionReset,
108+
/// The remote host is not reachable.
109+
#[unstable(feature = "io_error_more", issue = "86442")]
110+
HostUnreachable,
111+
/// The network containing the remote host is not reachable.
112+
#[unstable(feature = "io_error_more", issue = "86442")]
113+
NetworkUnreachable,
108114
/// The connection was aborted (terminated) by the remote server.
109115
#[stable(feature = "rust1", since = "1.0.0")]
110116
ConnectionAborted,
@@ -119,6 +125,9 @@ pub enum ErrorKind {
119125
/// local.
120126
#[stable(feature = "rust1", since = "1.0.0")]
121127
AddrNotAvailable,
128+
/// The system's networking is down.
129+
#[unstable(feature = "io_error_more", issue = "86442")]
130+
NetworkDown,
122131
/// The operation failed because a pipe was closed.
123132
#[stable(feature = "rust1", since = "1.0.0")]
124133
BrokenPipe,
@@ -129,6 +138,37 @@ pub enum ErrorKind {
129138
/// requested to not occur.
130139
#[stable(feature = "rust1", since = "1.0.0")]
131140
WouldBlock,
141+
/// A filesystem object is, unexpectedly, not a directory.
142+
///
143+
/// For example, a filesystem path was specified where one of the intermediate directory
144+
/// components was, in fact, a plain file.
145+
#[unstable(feature = "io_error_more", issue = "86442")]
146+
NotADirectory,
147+
/// The filesystem object is, unexpectedly, a directory.
148+
///
149+
/// A directory was specified when a non-directory was expected.
150+
#[unstable(feature = "io_error_more", issue = "86442")]
151+
IsADirectory,
152+
/// A non-empty directory was specified where an empty directory was expected.
153+
#[unstable(feature = "io_error_more", issue = "86442")]
154+
DirectoryNotEmpty,
155+
/// The filesystem or storage medium is read-only, but a write operation was attempted.
156+
#[unstable(feature = "io_error_more", issue = "86442")]
157+
ReadOnlyFilesystem,
158+
/// Loop in the filesystem; often, too many levels of symbolic links.
159+
///
160+
/// There was a loop (or excessively long chain) resolving a filesystem object.
161+
///
162+
/// On Unix this is usually the result of a symbolic link loop; or, of exceeding the
163+
/// system-specific limit on the depth of symlink traversal.
164+
#[unstable(feature = "io_error_more", issue = "86442")]
165+
FilesystemLoop,
166+
/// Stale network file handle
167+
///
168+
/// With some network filesystems, notably NFS, an open file (or directory) can be invalidated
169+
/// by problems with the network or server.
170+
#[unstable(feature = "io_error_more", issue = "86442")]
171+
StaleNetworkFileHandle,
132172
/// A parameter was incorrect.
133173
#[stable(feature = "rust1", since = "1.0.0")]
134174
InvalidInput,
@@ -158,6 +198,62 @@ pub enum ErrorKind {
158198
/// [`Ok(0)`]: Ok
159199
#[stable(feature = "rust1", since = "1.0.0")]
160200
WriteZero,
201+
/// The underlying storage (typically, a filesystem) is full.
202+
///
203+
/// This does not include out of quota errors.
204+
#[unstable(feature = "io_error_more", issue = "86442")]
205+
StorageFull,
206+
/// Seek on unseekable file
207+
///
208+
/// Seeking was attempted on an open file handle which is not suitable for seeking - for
209+
/// example, on Unix, a named pipe opened with `File::new`.
210+
#[unstable(feature = "io_error_more", issue = "86442")]
211+
NotSeekable,
212+
/// Filesystem quota was exceeded.
213+
#[unstable(feature = "io_error_more", issue = "86442")]
214+
FilesystemQuotaExceeded,
215+
/// File larger than allowed or supported.
216+
///
217+
/// This might arise from a hard limit of the underlying filesystem or file access API, or from
218+
/// an administratively imposed resource limitation. Simple disk full, and out of quota, have
219+
/// their own errors.
220+
#[unstable(feature = "io_error_more", issue = "86442")]
221+
FileTooLarge,
222+
/// Resource is busy.
223+
#[unstable(feature = "io_error_more", issue = "86442")]
224+
ResourceBusy,
225+
/// Executable file is busy.
226+
///
227+
/// An attempt was made to write to a file which is also in use as a running program. (Not all
228+
/// operating systems detect this situation.)
229+
#[unstable(feature = "io_error_more", issue = "86442")]
230+
ExecutableFileBusy,
231+
/// Deadlock (avoided)
232+
///
233+
/// A file locking operation would result in deadlock. This situation is typically detected, if
234+
/// at all, on a best-effort basis.
235+
#[unstable(feature = "io_error_more", issue = "86442")]
236+
Deadlock,
237+
/// Cross-device or cross-filesystem (hard) link or rename.
238+
#[unstable(feature = "io_error_more", issue = "86442")]
239+
CrossesDevices,
240+
/// Too many (hard) links to the same filesystem object.
241+
///
242+
/// The filesystem does not support making so many hardlinks to the same file.
243+
#[unstable(feature = "io_error_more", issue = "86442")]
244+
TooManyLinks,
245+
/// Filename too long.
246+
///
247+
/// The limit might be from the underlying filesystem or API, or an administratively imposed
248+
/// resource limit.
249+
#[unstable(feature = "io_error_more", issue = "86442")]
250+
FilenameTooLong,
251+
/// Program argument list too long.
252+
///
253+
/// When trying to run an external program, a system or process limit on the size of the
254+
/// arguments would have been exceeded.
255+
#[unstable(feature = "io_error_more", issue = "86442")]
256+
ArgumentListTooLong,
161257
/// This operation was interrupted.
162258
///
163259
/// Interrupted operations can typically be retried.
@@ -213,19 +309,39 @@ impl ErrorKind {
213309
AddrInUse => "address in use",
214310
AddrNotAvailable => "address not available",
215311
AlreadyExists => "entity already exists",
312+
ArgumentListTooLong => "argument list too long",
216313
BrokenPipe => "broken pipe",
314+
ResourceBusy => "resource busy",
217315
ConnectionAborted => "connection aborted",
218316
ConnectionRefused => "connection refused",
219317
ConnectionReset => "connection reset",
318+
CrossesDevices => "cross-device link or rename",
319+
Deadlock => "deadlock",
320+
DirectoryNotEmpty => "directory not empty",
321+
ExecutableFileBusy => "executable file busy",
322+
FilenameTooLong => "filename too long",
323+
FilesystemQuotaExceeded => "filesystem quota exceeded",
324+
FileTooLarge => "file too large",
325+
HostUnreachable => "host unreachable",
220326
Interrupted => "operation interrupted",
221327
InvalidData => "invalid data",
222328
InvalidInput => "invalid input parameter",
329+
IsADirectory => "is a directory",
330+
NetworkDown => "network down",
331+
NetworkUnreachable => "network unreachable",
332+
NotADirectory => "not a directory",
333+
StorageFull => "no storage space",
223334
NotConnected => "not connected",
224335
NotFound => "entity not found",
225336
Other => "other error",
226337
OutOfMemory => "out of memory",
227338
PermissionDenied => "permission denied",
339+
ReadOnlyFilesystem => "read-only filesystem or storage medium",
340+
StaleNetworkFileHandle => "stale network file handle",
341+
FilesystemLoop => "filesystem loop (e.g. symbolic link loop)",
342+
NotSeekable => "seek on unseekable file",
228343
TimedOut => "timed out",
344+
TooManyLinks => "too many links",
229345
Uncategorized => "uncategorized error",
230346
UnexpectedEof => "unexpected end of file",
231347
Unsupported => "unsupported",

library/std/src/sys/unix/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,40 @@ pub use libc::signal;
135135
pub fn decode_error_kind(errno: i32) -> ErrorKind {
136136
use ErrorKind::*;
137137
match errno as libc::c_int {
138+
libc::E2BIG => ArgumentListTooLong,
138139
libc::EADDRINUSE => AddrInUse,
139140
libc::EADDRNOTAVAIL => AddrNotAvailable,
141+
libc::EBUSY => ResourceBusy,
140142
libc::ECONNABORTED => ConnectionAborted,
141143
libc::ECONNREFUSED => ConnectionRefused,
142144
libc::ECONNRESET => ConnectionReset,
145+
libc::EDEADLK => Deadlock,
146+
libc::EDQUOT => FilesystemQuotaExceeded,
143147
libc::EEXIST => AlreadyExists,
148+
libc::EFBIG => FileTooLarge,
149+
libc::EHOSTUNREACH => HostUnreachable,
144150
libc::EINTR => Interrupted,
145151
libc::EINVAL => InvalidInput,
152+
libc::EISDIR => IsADirectory,
153+
libc::ELOOP => FilesystemLoop,
146154
libc::ENOENT => NotFound,
147155
libc::ENOMEM => OutOfMemory,
156+
libc::ENOSPC => StorageFull,
148157
libc::ENOSYS => Unsupported,
158+
libc::EMLINK => TooManyLinks,
159+
libc::ENAMETOOLONG => FilenameTooLong,
160+
libc::ENETDOWN => NetworkDown,
161+
libc::ENETUNREACH => NetworkUnreachable,
149162
libc::ENOTCONN => NotConnected,
163+
libc::ENOTDIR => NotADirectory,
164+
libc::ENOTEMPTY => DirectoryNotEmpty,
150165
libc::EPIPE => BrokenPipe,
166+
libc::EROFS => ReadOnlyFilesystem,
167+
libc::ESPIPE => NotSeekable,
168+
libc::ESTALE => StaleNetworkFileHandle,
151169
libc::ETIMEDOUT => TimedOut,
170+
libc::ETXTBSY => ExecutableFileBusy,
171+
libc::EXDEV => CrossesDevices,
152172

153173
libc::EACCES | libc::EPERM => PermissionDenied,
154174

library/std/src/sys/windows/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
9090
| c::ERROR_RUNLEVEL_SWITCH_TIMEOUT
9191
| c::ERROR_RUNLEVEL_SWITCH_AGENT_TIMEOUT => return TimedOut,
9292
c::ERROR_CALL_NOT_IMPLEMENTED => return Unsupported,
93+
| c::ERROR_RUNLEVEL_SWITCH_AGENT_TIMEOUT => return TimedOut,
94+
c::ERROR_CALL_NOT_IMPLEMENTED => return Unsupported,
95+
c::ERROR_HOST_UNREACHABLE => return HostUnreachable,
96+
c::ERROR_NETWORK_UNREACHABLE => return NetworkUnreachable,
97+
c::ERROR_DIRECTORY => return NotADirectory,
98+
c::ERROR_DIRECTORY_NOT_SUPPORTED => return IsADirectory,
99+
c::ERROR_DIR_NOT_EMPTY => return DirectoryNotEmpty,
100+
c::ERROR_WRITE_PROTECT => return ReadOnlyFilesystem,
101+
c::ERROR_DISK_FULL
102+
| c::ERROR_HANDLE_DISK_FULL => return StorageFull,
103+
c::ERROR_SEEK_ON_DEVICE => return NotSeekable,
104+
c::ERROR_DISK_QUOTA_EXCEEDED => return FilesystemQuotaExceeded,
105+
c::ERROR_FILE_TOO_LARGE => return FileTooLarge,
106+
c::ERROR_BUSY => return ResourceBusy,
107+
c::ERROR_POSSIBLE_DEADLOCK => return Deadlock,
108+
c::ERROR_NOT_SAME_DEVICE => return CrossesDevices,
109+
c::ERROR_TOO_MANY_LINKS => return TooManyLinks,
110+
c::ERROR_FILENAME_EXCED_RANGE => return FilenameTooLong,
93111
_ => {}
94112
}
95113

@@ -104,6 +122,9 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
104122
c::WSAENOTCONN => NotConnected,
105123
c::WSAEWOULDBLOCK => WouldBlock,
106124
c::WSAETIMEDOUT => TimedOut,
125+
c::WSAEHOSTUNREACH => HostUnreachable,
126+
c::WSAENETDOWN => NetworkDown,
127+
c::WSAENETUNREACH => NetworkUnreachable,
107128

108129
_ => Uncategorized,
109130
}

0 commit comments

Comments
 (0)