常见的系统错误


这是编写 Node.js 程序时经常遇到的系统错误列表。 有关完整的列表,请参阅 errno(3) 手册页

  • EACCES(权限被拒绝):试图以文件访问权限禁止的方式访问文件。

  • EADDRINUSE(地址已被使用):尝试将服务器(nethttp、或 https)绑定到本地地址失败,因为本地系统上的另一台服务器已经占用了该地址。

  • ECONNREFUSED(连接被拒绝):由于目标机器主动拒绝,无法建立连接。 这通常是由于尝试连接到在外部主机上处于非活动状态的服务。

  • ECONNRESET(对等方重置连接):连接被对等方强行关闭。。 这通常是由于超时或重新启动导致远程套接字上的连接丢失造成的。 通常通过 httpnet 模块遇到。

  • EEXIST(文件存在):现有文件是要求目标不存在的操作的目标。

  • EISDIR(是目录):操作期望文件,但给定的路径名​​是目录。

  • EMFILE(系统中打开的文件太多):已达到系统上允许的文件描述符的最大数量,并且在至少一个描述符被关闭之前无法满足对另一个描述符的请求。 同时打开多个文件时会遇到这种情况,尤其是在进程的文件描述符限制较低的系统(特别是 macOS)上。 要弥补低限制,则在将运行 Node.js 进程的同一个 shell 中运行 ulimit -n 2048

  • ENOENT(无此文件或目录):通常由 fs 操作引发,以指示指定路径名的组件不存在。 给定路径找不到任何实体(文件或目录)。

  • ENOTDIR(不是目录):给定路径名的组件存在,但不是期望的目录。 通常由 fs.readdir 引起。

  • ENOTEMPTY(目录不为空):有条目的目录是需要空目录的操作目标,通常是 fs.unlink

  • ENOTFOUND(域名系统查找失败):表示 EAI_NODATAEAI_NONAME 的域名系统失败。 这不是标准的 POSIX 错误。

  • EPERM(不允许操作):试图执行需要提升权限的操作。

  • EPIPE(断开的管道):对没有进程读取数据的管道、套接字或 FIFO 的写操作。 通常发生在 nethttp 层,表示正在写入的流的远程端已关闭。

  • ETIMEDOUT(操作超时):连接或发送请求失败,因为连接方在一段时间后没有正确地响应。 通常发生在 httpnet。 通常表明 socket.end() 没有被正确地调用。

This is a list of system errors commonly-encountered when writing a Node.js program. For a comprehensive list, see the errno(3) man page.

  • EACCES (Permission denied): An attempt was made to access a file in a way forbidden by its file access permissions.

  • EADDRINUSE (Address already in use): An attempt to bind a server (net, http, or https) to a local address failed due to another server on the local system already occupying that address.

  • ECONNREFUSED (Connection refused): No connection could be made because the target machine actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host.

  • ECONNRESET (Connection reset by peer): A connection was forcibly closed by a peer. This normally results from a loss of the connection on the remote socket due to a timeout or reboot. Commonly encountered via the http and net modules.

  • EEXIST (File exists): An existing file was the target of an operation that required that the target not exist.

  • EISDIR (Is a directory): An operation expected a file, but the given pathname was a directory.

  • EMFILE (Too many open files in system): Maximum number of file descriptors allowable on the system has been reached, and requests for another descriptor cannot be fulfilled until at least one has been closed. This is encountered when opening many files at once in parallel, especially on systems (in particular, macOS) where there is a low file descriptor limit for processes. To remedy a low limit, run ulimit -n 2048 in the same shell that will run the Node.js process.

  • ENOENT (No such file or directory): Commonly raised by fs operations to indicate that a component of the specified pathname does not exist. No entity (file or directory) could be found by the given path.

  • ENOTDIR (Not a directory): A component of the given pathname existed, but was not a directory as expected. Commonly raised by fs.readdir.

  • ENOTEMPTY (Directory not empty): A directory with entries was the target of an operation that requires an empty directory, usually fs.unlink.

  • ENOTFOUND (DNS lookup failed): Indicates a DNS failure of either EAI_NODATA or EAI_NONAME. This is not a standard POSIX error.

  • EPERM (Operation not permitted): An attempt was made to perform an operation that requires elevated privileges.

  • EPIPE (Broken pipe): A write on a pipe, socket, or FIFO for which there is no process to read the data. Commonly encountered at the net and http layers, indicative that the remote side of the stream being written to has been closed.

  • ETIMEDOUT (Operation timed out): A connect or send request failed because the connected party did not properly respond after a period of time. Usually encountered by http or net. Often a sign that a socket.end() was not properly called.