package luv

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Error handling.

See Error handling in the user guide and Error handling in libuv.

type t = [
  1. | `E2BIG
  2. | `EACCES
  3. | `EADDRINUSE
  4. | `EADDRNOTAVAIL
  5. | `EAFNOSUPPORT
  6. | `EAGAIN
  7. | `EAI_ADDRFAMILY
  8. | `EAI_AGAIN
  9. | `EAI_BADFLAGS
  10. | `EAI_BADHINTS
  11. | `EAI_CANCELED
  12. | `EAI_FAIL
  13. | `EAI_FAMILY
  14. | `EAI_MEMORY
  15. | `EAI_NODATA
  16. | `EAI_NONAME
  17. | `EAI_OVERFLOW
  18. | `EAI_PROTOCOL
  19. | `EAI_SERVICE
  20. | `EAI_SOCKTYPE
  21. | `EALREADY
  22. | `EBADF
  23. | `EBUSY
  24. | `ECANCELED
  25. | `ECONNABORTED
  26. | `ECONNREFUSED
  27. | `ECONNRESET
  28. | `EDESTADDRREQ
  29. | `EEXIST
  30. | `EFAULT
  31. | `EFBIG
  32. | `EFTYPE
  33. | `EHOSTUNREACH
  34. | `EILSEQ
  35. | `EINTR
  36. | `EINVAL
  37. | `EIO
  38. | `EISCONN
  39. | `EISDIR
  40. | `ELOOP
  41. | `EMFILE
  42. | `EMSGSIZE
  43. | `ENAMETOOLONG
  44. | `ENETDOWN
  45. | `ENETUNREACH
  46. | `ENFILE
  47. | `ENOBUFS
  48. | `ENODATA
  49. | `ENODEV
  50. | `ENOENT
  51. | `ENOMEM
  52. | `ENONET
  53. | `ENOPROTOOPT
  54. | `ENOSPC
  55. | `ENOSYS
  56. | `ENOTCONN
  57. | `ENOTDIR
  58. | `ENOTEMPTY
  59. | `ENOTSOCK
  60. | `ENOTSUP
  61. | `ENOTTY
  62. | `ENXIO
  63. | `EOF
  64. | `EOVERFLOW
  65. | `EPERM
  66. | `EPIPE
  67. | `EPROTO
  68. | `EPROTONOSUPPORT
  69. | `EPROTOTYPE
  70. | `ERANGE
  71. | `EROFS
  72. | `ESHUTDOWN
  73. | `ESOCKTNOSUPPORT
  74. | `ESPIPE
  75. | `ESRCH
  76. | `ETIMEDOUT
  77. | `ETXTBSY
  78. | `EUNATCH
  79. | `EXDEV
  80. | `UNKNOWN
]

Error codes returned by libuv functions.

Binds libuv error codes, which resemble Unix error codes.

`EFTYPE is available since Luv 0.5.5 and libuv 1.21.0.

`EILSEQ is available since libuv 1.32.0.

`ENODATA is available since Luv 0.5.13 and libuv 1.45.0.

`ENOTTY is available since Luv 0.5.5 and libuv 1.16.0.

`EOVERFLOW and `ESOCKTNOSUPPORT are available since Luv 0.5.9 and libuv 1.42.0.

`EUNATCH is available since Luv 0.5.13 and libuv 1.46.0.

Feature checks:

  • Luv.Require.(has eftype)
  • Luv.Require.(has eilseq)
  • Luv.Require.(has enotty)
  • Luv.Require.(has enodata)
  • Luv.Require.(has eoverflow)
  • Luv.Require.(has esocktnosupport)
  • Luv.Require.(has eunatch)
val strerror : t -> string

Returns the error message corresponding to the given error code.

Binds uv_strerror_r.

If you are using libuv 1.21.0 or earlier, Luv.Error.strerror `UNKNOWN slowly leaks memory.

val err_name : t -> string

Returns the name of the given error code.

Binds uv_err_name_r.

If you are using libuv 1.21.0 or earlier, Luv.Error.err_name `UNKNOWN slowly leaks memory.

val translate_sys_error : int -> t

Converts a system error code to a libuv error code.

Binds uv_translate_sys_error.

Requires libuv 1.10.0.

Feature check: Luv.Require.(has translate_sys_error)

val set_on_unhandled_exception : (exn -> unit) -> unit

If user code terminates a callback by raising an exception, the exception cannot be allowed to go up the call stack, because the callback was called by libuv (rather than OCaml code), and the exception would disrupt libuv book-keeping. Luv instead passes the exception to a global Luv exception handler. Luv.Error.set_on_unhandled_exception f replaces this exception handler with f.

For example, in

Luv.Error.set_on_unhandled_exception f;
Luv.File.mkdir "foo" (fun _ -> raise Exit);

the exception Exit is passed to f when mkdir calls its callback.

It is recommended to avoid letting exceptions escape from callbacks in this way.

The default behavior, if Luv.Error.set_on_unhandled_exception is never called, is for Luv to print the exception to STDERR and exit the process with exit code 2.

It is recommended not to call Luv.Error.set_on_unhandled_exception from libraries based on Luv, but, instead, to leave the decision on how to handle exceptions up to the final application.

OCaml

Innovation. Community. Security.