# Error handling

In libuv errors are negative numbered constants. As a rule of thumb, whenever there is a status parameter, or an API functions returns an integer, a negative number will imply an error.

When a function which takes a callback returns an error, the callback will never be called.

Note

Implementation detail: on Unix error codes are the negated errno (or -errno), while on Windows they are defined by libuv to arbitrary negative numbers.

## Error constants

UV_E2BIG

  argument list too long

UV_EACCES

  permission denied

UV_EADDRINUSE

  address already in use

UV_EADDRNOTAVAIL

  address not available

UV_EAFNOSUPPORT

  address family not supported

UV_EAGAIN

  resource temporarily unavailable

UV_EAI_ADDRFAMILY

  address family not supported

UV_EAI_AGAIN

  temporary failure

UV_EAI_BADFLAGS

  bad ai_flags value

UV_EAI_BADHINTS

  invalid value for hints

UV_EAI_CANCELED

  request canceled

UV_EAI_FAIL

  permanent failure

UV_EAI_FAMILY

  ai_family not supported

UV_EAI_MEMORY

  out of memory

UV_EAI_NODATA

  no address

UV_EAI_NONAME

  unknown node or service

UV_EAI_OVERFLOW

  argument buffer overflow

UV_EAI_PROTOCOL

  resolved protocol is unknown

UV_EAI_SERVICE

  service not available for socket type

UV_EAI_SOCKTYPE

  socket type not supported

UV_EALREADY

  connection already in progress

UV_EBADF

  bad file descriptor

UV_EBUSY

  resource busy or locked

UV_ECANCELED

  operation canceled

UV_ECHARSET

  invalid Unicode character

UV_ECONNABORTED

  software caused connection abort

UV_ECONNREFUSED

  connection refused

UV_ECONNRESET

  connection reset by peer

UV_EDESTADDRREQ

  destination address required

UV_EEXIST

  file already exists

UV_EFAULT

  bad address in system call argument

UV_EFBIG

  file too large

UV_EHOSTUNREACH

  host is unreachable

UV_EINTR

  interrupted system call

UV_EINVAL

  invalid argument

UV_EIO

  i/o error

UV_EISCONN

  socket is already connected

UV_EISDIR

  illegal operation on a directory

UV_ELOOP

  too many symbolic links encountered

UV_EMFILE

  too many open files

UV_EMSGSIZE

  message too long

UV_ENAMETOOLONG

  name too long

UV_ENETDOWN

  network is down

UV_ENETUNREACH

  network is unreachable

UV_ENFILE

  file table overflow

UV_ENOBUFS

  no buffer space available

UV_ENODEV

  no such device

UV_ENOENT

  no such file or directory

UV_ENOMEM

  not enough memory

UV_ENONET

  machine is not on the network

UV_ENOPROTOOPT

  protocol not available

UV_ENOSPC

  no space left on device

UV_ENOSYS

  function not implemented

UV_ENOTCONN

  socket is not connected

UV_ENOTDIR

  not a directory

UV_ENOTEMPTY

  directory not empty

UV_ENOTSOCK

  socket operation on non-socket

UV_ENOTSUP

  operation not supported on socket

UV_EPERM

  operation not permitted

UV_EPIPE

  broken pipe

UV_EPROTO

  protocol error

UV_EPROTONOSUPPORT

  protocol not supported

UV_EPROTOTYPE

  protocol wrong type for socket

UV_ERANGE

  result too large

UV_EROFS

  read-only file system

UV_ESHUTDOWN

  cannot send after transport endpoint shutdown

UV_ESPIPE

  invalid seek

UV_ESRCH

  no such process

UV_ETIMEDOUT

  connection timed out

UV_ETXTBSY

  text file is busy

UV_EXDEV

  cross-device link not permitted

UV_UNKNOWN

  unknown error

UV_EOF

  end of file

UV_ENXIO

  no such device or address

UV_EMLINK

  too many links

UV_ENOTTY

  inappropriate ioctl for device

UV_EFTYPE

  inappropriate file type or format

UV_EILSEQ

  illegal byte sequence

## API

UV_ERRNO_MAP(iter_macro)

  Macro that expands to a series of invocations of iter_macro for each of the error constants above. iter_macro is invoked with two arguments: the name of the error constant without the UV_ prefix, and the error message string literal.

const char *uv_strerror(int err)

  Returns the error message for the given error code. Leaks a few bytes of memory when you call it with an unknown error code.

char *uv_strerror_r(int err, char *buf, size_t buflen)

  Returns the error message for the given error code. The zero-terminated message is stored in the user-supplied buffer buf of at most buflen bytes.

  New in version 1.22.0.

const char *uv_err_name(int err)

  Returns the error name for the given error code. Leaks a few bytes of memory when you call it with an unknown error code.

char *uv_err_name_r(int err, char *buf, size_t buflen)

  Returns the error name for the given error code. The zero-terminated name is stored in the user-supplied buffer buf of at most buflen bytes.

  New in version 1.22.0.

int uv_translate_sys_error(int sys_errno)

  Returns the libuv error code equivalent to the given platform dependent error code: POSIX error codes on Unix (the ones stored in errno), and Win32 error codes on Windows (those returned by GetLastError() or WSAGetLastError()).

  If sys_errno is already a libuv error, it is simply returned.

  Changed in version 1.10.0: function declared public.