Module

When an operating system encounters an error, it typically reports the error as an integer error code:

$ ls nosuch.txt
ls: cannot access 'nosuch.txt': No such file or directory
$ echo $? # Code for last error.
2

When the Ruby interpreter interacts with the operating system and receives such an error code (e.g., 2), it maps the code to a particular Ruby exception class (e.g., Errno::ENOENT):

File.open('nosuch.txt')
# => No such file or directory @ rb_sysopen - nosuch.txt (Errno::ENOENT)

Each such class is:

  • A nested class in this module, Errno.

  • A subclass of class SystemCallError.

  • Associated with an error code.

Thus:

Errno::ENOENT.superclass # => SystemCallError
Errno::ENOENT::Errno     # => 2

The names of nested classes are returned by method Errno.constants:

Errno.constants.size         # => 158
Errno.constants.sort.take(5) # => [:E2BIG, :EACCES, :EADDRINUSE, :EADDRNOTAVAIL, :EADV]

As seen above, the error code associated with each class is available as the value of a constant; the value for a particular class may vary among operating systems. If the class is not needed for the particular operating system, the value is zero:

Errno::ENOENT::Errno      # => 2
Errno::ENOTCAPABLE::Errno # => 0
Constants

No error

“Argument list too long” error

“Permission denied” error

“Address already in use” error

“Address not available” error

“Advertise error” error

“Address family not supported” error

“Resource temporarily unavailable, try again (may be the same value as EWOULDBLOCK)” error

“Connection already in progress” error

“Authentication error” error

“Bad CPU type in executable” error

“Bad exchange” error

“Bad executable” error

“Bad file descriptor” error

“File descriptor in bad state” error

“Malformed Macho file” error

“Bad message” error

“Invalid request descriptor” error

“RPC struct is bad” error

“Invalid request code” error

“Invalid slot” error

“Bad font file format” error

“Device or resource busy” error

“Operation canceled” error

“Not permitted in capability mode” error

“No child processes” error

“Channel number out of range” error

“Communication error on send” error

“Connection aborted” error

“Connection refused” error

“Connection reset” error

“Resource deadlock avoided” error

“File locking deadlock error” error

“Destination address required” error

“Device error; e.g., printer paper out” error

“Mathematics argument out of domain of function” error

“Improper function use” error

“RFS specific error” error

“Disk quota exceeded” error

“File exists” error

“Bad address” error

“File too large” error

“Invalid file type or format” error

“Host is down” error

“Host is unreachable” error

“Memory page has hardware error” error

“Identifier removed” error

“Invalid or incomplete multibyte or wide character” error

“Operation in progress” error

“Interrupted function call” error

“Invalid argument” error

EIO

“Input/output error” error

“IPsec processing failure” error

“Socket is connected” error

“Is a directory” error

“Is a named file type” error

“Key has expired” error

“Key was rejected by service” error

“Key has been revoked” error

“Level 2 halted” error

“Level 2 not synchronized” error

“Level 3 halted” error

“Level 3 reset” error

“Cannot access a needed shared library” error

“Accessing a corrupted shared library” error

“Cannot exec a shared library directly” error

“Attempting to link in too many shared libraries” error

“.lib section in a.out corrupted” error

“Link number out of range” error

“Too many levels of symbolic links” error

“Wrong medium type” error

“Too many open files” error

“Too many links” error

“Message too long” error

“Multihop attempted” error

“Filename too long” error

“No XENIX semaphores available” error

“Need authenticator” error

“Network is down” error

“Connection aborted by network” error

“Network unreachable” error

“Too many open files in system” error

“No anode” error

“Attribute not found” error

“No buffer space available” error

“No CSI structure available” error

“No data available” error

“No such device” error

“No such file or directory” error

“Exec format error” error

“Required key not available” error

“No locks available” error

“Link has been severed” error

“No medium found” error

“Not enough space/cannot allocate memory” error

“No message of the desired type” error

“Machine is not on the network” error

“Package not installed” error

“No such policy” error

“Protocol not available” error

“No space left on device” error

“No STREAM resources” error

“Not a STREAM” error

“Functionality not implemented” error

“Block device required” error

“Capabilities insufficient” error

“The socket is not connected” error

“Not a directory” error

“Directory not empty” error

“Not a XENIX named type file” error

“State not recoverable” error

“Not a socket” error

“Operation not supported” error

“Inappropriate I/O control operation” error

“Name not unique on network” error

“No such device or address” error

“Operation not supported on socket” error

“Value too large to be stored in data type” error

“Owner died” error

“Operation not permitted” error

“Protocol family not supported” error

“Broken pipe” error

“Too many processes” error

“Bad procedure for program” error

“Program version wrong” error

“RPC program isn’t available” error

“Protocol error” error

“Protocol not supported” error

“Protocol wrong type for socket” error

“Device power is off” error

“Interface output queue is full” error

“Result too large” error

“Remote address changed” error

“Object is remote” error

“Remote I/O error” error

“Interrupted system call should be restarted” error

“Operation not possible due to RF-kill” error

“Read-only file system” error

“RPC version wrong” error

“Shared library version mismatch” error

“Cannot send after transport endpoint shutdown” error

“Socket type not supported” error

“Illegal seek” error

“No such process” error

“Server mount error” error

“Stale file handle” error

“Streams pipe error” error

“Timer expired” error

“Connection timed out” error

cannot splice“ error

“Text file busy” error

“Structure needs cleaning” error

“Protocol driver not attached” error

“Too many users” error

“Operation would block” error

“Invalid cross-device link” error

“Exchange full” error

“Largest errno value” error