Module errno
The errno module is typically used within a function or within a Lua
program, in association with a module whose functions can return
operating-system errors, such as fio.
Below is a list of all errno functions.
Name | Use |
|---|---|
Get an error number for the last OS-related function | |
Get an error message for the corresponding error number |
Return an error number for the last operating-system-related function,
or 0. To invoke it, simply say errno(), without the module name.
Return type
integer
Return a string, given an error number. The string will contain the text
of the conventional error message for the current operating system. If
code is not supplied, the error message will be for the last
operating-system-related function, or 0.
Parameters:
code(integer) — number of an operating-system error
Return type
string
Example:
This function displays the result of a call to fio.open()
which causes error 2 (errno.ENOENT). The display includes the error
number, the associated error string, and the error name.
tarantool> function f()> local fio = require('fio')> local errno = require('errno')> fio.open('no_such_file')> print('errno() = ' .. errno())> print('errno.strerror() = ' .. errno.strerror())> local t = getmetatable(errno).__index> for k, v in pairs(t) do> if v == errno() then> print('errno() constant = ' .. k)> end> end> end---...tarantool> f()errno() = 2errno.strerror() = No such file or directoryerrno() constant = ENOENT---...
To see all possible error names stored in the errno metatable, say
getmetatable(errno) (output abridged):
tarantool> getmetatable(errno)---- __newindex: 'function: 0x41666a38'__call: 'function: 0x41666890'__index:ENOLINK: 67EMSGSIZE: 90EOVERFLOW: 75ENOTCONN: 107EFAULT: 14EOPNOTSUPP: 95EEXIST: 17ENOSR: 63ENOTSOCK: 88EDESTADDRREQ: 89<...>...