Sophie

Sophie

distrib > Mageia > 6 > x86_64 > by-pkgid > 4642cf16cdfb16e1cdaefd0999c41911 > files > 57

nodejs-docs-6.17.1-8.mga6.noarch.rpm

{
  "source": "doc/api/errors.md",
  "introduced_in": "v4.0.0",
  "classes": [
    {
      "textRaw": "Class: Error",
      "type": "class",
      "name": "Error",
      "desc": "<p>A generic JavaScript <code>Error</code> object that does not denote any specific\ncircumstance of why the error occurred. <code>Error</code> objects capture a &quot;stack trace&quot;\ndetailing the point in the code at which the <code>Error</code> was instantiated, and may\nprovide a text description of the error.</p>\n<p>All errors generated by Node.js, including all System and JavaScript errors,\nwill either be instances of, or inherit from, the <code>Error</code> class.</p>\n",
      "methods": [
        {
          "textRaw": "Error.captureStackTrace(targetObject[, constructorOpt])",
          "type": "method",
          "name": "captureStackTrace",
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`targetObject` {Object} ",
                  "name": "targetObject",
                  "type": "Object"
                },
                {
                  "textRaw": "`constructorOpt` {Function} ",
                  "name": "constructorOpt",
                  "type": "Function",
                  "optional": true
                }
              ]
            },
            {
              "params": [
                {
                  "name": "targetObject"
                },
                {
                  "name": "constructorOpt",
                  "optional": true
                }
              ]
            }
          ],
          "desc": "<p>Creates a <code>.stack</code> property on <code>targetObject</code>, which when accessed returns\na string representing the location in the code at which\n<code>Error.captureStackTrace()</code> was called.</p>\n<pre><code class=\"lang-js\">const myObject = {};\nError.captureStackTrace(myObject);\nmyObject.stack;  // similar to `new Error().stack`\n</code></pre>\n<p>The first line of the trace, instead of being prefixed with <code>ErrorType:\nmessage</code>, will be the result of calling <code>targetObject.toString()</code>.</p>\n<p>The optional <code>constructorOpt</code> argument accepts a function. If given, all frames\nabove <code>constructorOpt</code>, including <code>constructorOpt</code>, will be omitted from the\ngenerated stack trace.</p>\n<p>The <code>constructorOpt</code> argument is useful for hiding implementation\ndetails of error generation from an end user. For instance:</p>\n<pre><code class=\"lang-js\">function MyError() {\n  Error.captureStackTrace(this, MyError);\n}\n\n// Without passing MyError to captureStackTrace, the MyError\n// frame would show up in the .stack property. By passing\n// the constructor, we omit that frame, and retain all frames below it.\nnew MyError().stack;\n</code></pre>\n"
        }
      ],
      "properties": [
        {
          "textRaw": "`stackTraceLimit` {number} ",
          "type": "number",
          "name": "stackTraceLimit",
          "desc": "<p>The <code>Error.stackTraceLimit</code> property specifies the number of stack frames\ncollected by a stack trace (whether generated by <code>new Error().stack</code> or\n<code>Error.captureStackTrace(obj)</code>).</p>\n<p>The default value is <code>10</code> but may be set to any valid JavaScript number. Changes\nwill affect any stack trace captured <em>after</em> the value has been changed.</p>\n<p>If set to a non-number value, or set to a negative number, stack traces will\nnot capture any frames.</p>\n"
        },
        {
          "textRaw": "`message` {string} ",
          "type": "string",
          "name": "message",
          "desc": "<p>The <code>error.message</code> property is the string description of the error as set by calling <code>new Error(message)</code>.\nThe <code>message</code> passed to the constructor will also appear in the first line of\nthe stack trace of the <code>Error</code>, however changing this property after the\n<code>Error</code> object is created <em>may not</em> change the first line of the stack trace\n(for example, when <code>error.stack</code> is read before this property is changed).</p>\n<pre><code class=\"lang-js\">const err = new Error(&#39;The message&#39;);\nconsole.error(err.message);\n// Prints: The message\n</code></pre>\n"
        },
        {
          "textRaw": "`stack` {string} ",
          "type": "string",
          "name": "stack",
          "desc": "<p>The <code>error.stack</code> property is a string describing the point in the code at which\nthe <code>Error</code> was instantiated.</p>\n<p>For example:</p>\n<pre><code class=\"lang-txt\">Error: Things keep happening!\n   at /home/gbusey/file.js:525:2\n   at Frobnicator.refrobulate (/home/gbusey/business-logic.js:424:21)\n   at Actor.&lt;anonymous&gt; (/home/gbusey/actors.js:400:8)\n   at increaseSynergy (/home/gbusey/actors.js:701:6)\n</code></pre>\n<p>The first line is formatted as <code>&lt;error class name&gt;: &lt;error message&gt;</code>, and\nis followed by a series of stack frames (each line beginning with &quot;at &quot;).\nEach frame describes a call site within the code that lead to the error being\ngenerated. V8 attempts to display a name for each function (by variable name,\nfunction name, or object method name), but occasionally it will not be able to\nfind a suitable name. If V8 cannot determine a name for the function, only\nlocation information will be displayed for that frame. Otherwise, the\ndetermined function name will be displayed with location information appended\nin parentheses.</p>\n<p>It is important to note that frames are <strong>only</strong> generated for JavaScript\nfunctions. If, for example, execution synchronously passes through a C++ addon\nfunction called <code>cheetahify</code>, which itself calls a JavaScript function, the\nframe representing the <code>cheetahify</code> call will <strong>not</strong> be present in the stack\ntraces:</p>\n<pre><code class=\"lang-js\">const cheetahify = require(&#39;./native-binding.node&#39;);\n\nfunction makeFaster() {\n  // cheetahify *synchronously* calls speedy.\n  cheetahify(function speedy() {\n    throw new Error(&#39;oh no!&#39;);\n  });\n}\n\nmakeFaster(); // will throw:\n// /home/gbusey/file.js:6\n//     throw new Error(&#39;oh no!&#39;);\n//           ^\n// Error: oh no!\n//     at speedy (/home/gbusey/file.js:6:11)\n//     at makeFaster (/home/gbusey/file.js:5:3)\n//     at Object.&lt;anonymous&gt; (/home/gbusey/file.js:10:1)\n//     at Module._compile (module.js:456:26)\n//     at Object.Module._extensions..js (module.js:474:10)\n//     at Module.load (module.js:356:32)\n//     at Function.Module._load (module.js:312:12)\n//     at Function.Module.runMain (module.js:497:10)\n//     at startup (node.js:119:16)\n//     at node.js:906:3\n</code></pre>\n<p>The location information will be one of:</p>\n<ul>\n<li><code>native</code>, if the frame represents a call internal to V8 (as in <code>[].forEach</code>).</li>\n<li><code>plain-filename.js:line:column</code>, if the frame represents a call internal\n to Node.js.</li>\n<li><code>/absolute/path/to/file.js:line:column</code>, if the frame represents a call in\na user program, or its dependencies.</li>\n</ul>\n<p>The string representing the stack trace is lazily generated when the\n<code>error.stack</code> property is <strong>accessed</strong>.</p>\n<p>The number of frames captured by the stack trace is bounded by the smaller of\n<code>Error.stackTraceLimit</code> or the number of available frames on the current event\nloop tick.</p>\n<p>System-level errors are generated as augmented <code>Error</code> instances, which are\ndetailed <a href=\"#errors_system_errors\">here</a>.</p>\n"
        }
      ],
      "signatures": [
        {
          "params": [
            {
              "textRaw": "`message` {string} ",
              "name": "message",
              "type": "string"
            }
          ],
          "desc": "<p>Creates a new <code>Error</code> object and sets the <code>error.message</code> property to the\nprovided text message. If an object is passed as <code>message</code>, the text message\nis generated by calling <code>message.toString()</code>. The <code>error.stack</code> property will\nrepresent the point in the code at which <code>new Error()</code> was called. Stack traces\nare dependent on <a href=\"https://github.com/v8/v8/wiki/Stack-Trace-API\">V8&#39;s stack trace API</a>. Stack traces extend only to either\n(a) the beginning of <em>synchronous code execution</em>, or (b) the number of frames\ngiven by the property <code>Error.stackTraceLimit</code>, whichever is smaller.</p>\n"
        },
        {
          "params": [
            {
              "name": "message"
            }
          ],
          "desc": "<p>Creates a new <code>Error</code> object and sets the <code>error.message</code> property to the\nprovided text message. If an object is passed as <code>message</code>, the text message\nis generated by calling <code>message.toString()</code>. The <code>error.stack</code> property will\nrepresent the point in the code at which <code>new Error()</code> was called. Stack traces\nare dependent on <a href=\"https://github.com/v8/v8/wiki/Stack-Trace-API\">V8&#39;s stack trace API</a>. Stack traces extend only to either\n(a) the beginning of <em>synchronous code execution</em>, or (b) the number of frames\ngiven by the property <code>Error.stackTraceLimit</code>, whichever is smaller.</p>\n"
        }
      ]
    },
    {
      "textRaw": "Class: RangeError",
      "type": "class",
      "name": "RangeError",
      "desc": "<p>A subclass of <code>Error</code> that indicates that a provided argument was not within the\nset or range of acceptable values for a function; whether that is a numeric\nrange, or outside the set of options for a given function parameter.</p>\n<p>For example:</p>\n<pre><code class=\"lang-js\">require(&#39;net&#39;).connect(-1);\n// throws &quot;RangeError: &quot;port&quot; option should be &gt;= 0 and &lt; 65536: -1&quot;\n</code></pre>\n<p>Node.js will generate and throw <code>RangeError</code> instances <em>immediately</em> as a form\nof argument validation.</p>\n"
    },
    {
      "textRaw": "Class: ReferenceError",
      "type": "class",
      "name": "ReferenceError",
      "desc": "<p>A subclass of <code>Error</code> that indicates that an attempt is being made to access a\nvariable that is not defined. Such errors commonly indicate typos in code, or\nan otherwise broken program.</p>\n<p>While client code may generate and propagate these errors, in practice, only V8\nwill do so.</p>\n<pre><code class=\"lang-js\">doesNotExist;\n// throws ReferenceError, doesNotExist is not a variable in this program.\n</code></pre>\n<p>Unless an application is dynamically generating and running code,\n<code>ReferenceError</code> instances should always be considered a bug in the code\nor its dependencies.</p>\n"
    },
    {
      "textRaw": "Class: SyntaxError",
      "type": "class",
      "name": "SyntaxError",
      "desc": "<p>A subclass of <code>Error</code> that indicates that a program is not valid JavaScript.\nThese errors may only be generated and propagated as a result of code\nevaluation. Code evaluation may happen as a result of <code>eval</code>, <code>Function</code>,\n<code>require</code>, or <a href=\"vm.html\">vm</a>. These errors are almost always indicative of a broken\nprogram.</p>\n<pre><code class=\"lang-js\">try {\n  require(&#39;vm&#39;).runInThisContext(&#39;binary ! isNotOk&#39;);\n} catch (err) {\n  // err will be a SyntaxError\n}\n</code></pre>\n<p><code>SyntaxError</code> instances are unrecoverable in the context that created them –\nthey may only be caught by other contexts.</p>\n"
    },
    {
      "textRaw": "Class: TypeError",
      "type": "class",
      "name": "TypeError",
      "desc": "<p>A subclass of <code>Error</code> that indicates that a provided argument is not an\nallowable type. For example, passing a function to a parameter which expects a\nstring would be considered a TypeError.</p>\n<pre><code class=\"lang-js\">require(&#39;url&#39;).parse(() =&gt; { });\n// throws TypeError, since it expected a string\n</code></pre>\n<p>Node.js will generate and throw <code>TypeError</code> instances <em>immediately</em> as a form\nof argument validation.</p>\n"
    }
  ],
  "miscs": [
    {
      "textRaw": "Errors",
      "name": "Errors",
      "introduced_in": "v4.0.0",
      "type": "misc",
      "desc": "<p>Applications running in Node.js will generally experience four categories of\nerrors:</p>\n<ul>\n<li>Standard JavaScript errors such as:<ul>\n<li>{EvalError} : thrown when a call to <code>eval()</code> fails.</li>\n<li>{SyntaxError} : thrown in response to improper JavaScript language\nsyntax.</li>\n<li>{RangeError} : thrown when a value is not within an expected range</li>\n<li>{ReferenceError} : thrown when using undefined variables</li>\n<li>{TypeError} : thrown when passing arguments of the wrong type</li>\n<li>{URIError} : thrown when a global URI handling function is misused.</li>\n</ul>\n</li>\n<li>System errors triggered by underlying operating system constraints such\nas attempting to open a file that does not exist, attempting to send data\nover a closed socket, etc;</li>\n<li>And User-specified errors triggered by application code.</li>\n<li>Assertion Errors are a special class of error that can be triggered whenever\nNode.js detects an exceptional logic violation that should never occur. These\nare raised typically by the <code>assert</code> module.</li>\n</ul>\n<p>All JavaScript and System errors raised by Node.js inherit from, or are\ninstances of, the standard JavaScript {Error} class and are guaranteed\nto provide <em>at least</em> the properties available on that class.</p>\n",
      "miscs": [
        {
          "textRaw": "Error Propagation and Interception",
          "name": "Error Propagation and Interception",
          "type": "misc",
          "desc": "<p>Node.js supports several mechanisms for propagating and handling errors that\noccur while an application is running. How these errors are reported and\nhandled depends entirely on the type of Error and the style of the API that is\ncalled.</p>\n<p>All JavaScript errors are handled as exceptions that <em>immediately</em> generate\nand throw an error using the standard JavaScript <code>throw</code> mechanism. These\nare handled using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch\"><code>try / catch</code> construct</a> provided by the JavaScript\nlanguage.</p>\n<pre><code class=\"lang-js\">// Throws with a ReferenceError because z is undefined\ntry {\n  const m = 1;\n  const n = m + z;\n} catch (err) {\n  // Handle the error here.\n}\n</code></pre>\n<p>Any use of the JavaScript <code>throw</code> mechanism will raise an exception that\n<em>must</em> be handled using <code>try / catch</code> or the Node.js process will exit\nimmediately.</p>\n<p>With few exceptions, <em>Synchronous</em> APIs (any blocking method that does not\naccept a <code>callback</code> function, such as <a href=\"fs.html#fs_fs_readfilesync_file_options\"><code>fs.readFileSync</code></a>), will use <code>throw</code>\nto report errors.</p>\n<p>Errors that occur within <em>Asynchronous APIs</em> may be reported in multiple ways:</p>\n<ul>\n<li>Most asynchronous methods that accept a <code>callback</code> function will accept an\n<code>Error</code> object passed as the first argument to that function. If that first\nargument is not <code>null</code> and is an instance of <code>Error</code>, then an error occurred\nthat should be handled.</li>\n</ul>\n<!-- eslint-disable no-useless-return -->\n<pre><code class=\"lang-js\">  const fs = require(&#39;fs&#39;);\n  fs.readFile(&#39;a file that does not exist&#39;, (err, data) =&gt; {\n    if (err) {\n      console.error(&#39;There was an error reading the file!&#39;, err);\n      return;\n    }\n    // Otherwise handle the data\n  });\n</code></pre>\n<ul>\n<li><p>When an asynchronous method is called on an object that is an <code>EventEmitter</code>,\nerrors can be routed to that object&#39;s <code>&#39;error&#39;</code> event.</p>\n<pre><code class=\"lang-js\">const net = require(&#39;net&#39;);\nconst connection = net.connect(&#39;localhost&#39;);\n\n// Adding an &#39;error&#39; event handler to a stream:\nconnection.on(&#39;error&#39;, (err) =&gt; {\n  // If the connection is reset by the server, or if it can&#39;t\n  // connect at all, or on any sort of error encountered by\n  // the connection, the error will be sent here.\n  console.error(err);\n});\n\nconnection.pipe(process.stdout);\n</code></pre>\n</li>\n<li><p>A handful of typically asynchronous methods in the Node.js API may still\nuse the <code>throw</code> mechanism to raise exceptions that must be handled using\n<code>try / catch</code>. There is no comprehensive list of such methods; please\nrefer to the documentation of each method to determine the appropriate\nerror handling mechanism required.</p>\n</li>\n</ul>\n<p>The use of the <code>&#39;error&#39;</code> event mechanism is most common for <a href=\"stream.html\">stream-based</a>\nand <a href=\"events.html#events_class_eventemitter\">event emitter-based</a> APIs, which themselves represent a series of\nasynchronous operations over time (as opposed to a single operation that may\npass or fail).</p>\n<p>For <em>all</em> <code>EventEmitter</code> objects, if an <code>&#39;error&#39;</code> event handler is not\nprovided, the error will be thrown, causing the Node.js process to report an\nunhandled exception and crash unless either: The <a href=\"domain.html\"><code>domain</code></a> module is used\nappropriately or a handler has been registered for the\n<a href=\"process.html#process_event_uncaughtexception\"><code>process.on(&#39;uncaughtException&#39;)</code></a> event.</p>\n<pre><code class=\"lang-js\">const EventEmitter = require(&#39;events&#39;);\nconst ee = new EventEmitter();\n\nsetImmediate(() =&gt; {\n  // This will crash the process because no &#39;error&#39; event\n  // handler has been added.\n  ee.emit(&#39;error&#39;, new Error(&#39;This will crash&#39;));\n});\n</code></pre>\n<p>Errors generated in this way <em>cannot</em> be intercepted using <code>try / catch</code> as\nthey are thrown <em>after</em> the calling code has already exited.</p>\n<p>Developers must refer to the documentation for each method to determine\nexactly how errors raised by those methods are propagated.</p>\n",
          "miscs": [
            {
              "textRaw": "Node.js style callbacks",
              "name": "Node.js style callbacks",
              "type": "misc",
              "desc": "<p>Most asynchronous methods exposed by the Node.js core API follow an idiomatic\npattern referred to as a &quot;Node.js style callback&quot;. With this pattern, a\ncallback function is passed to the method as an argument. When the operation\neither completes or an error is raised, the callback function is called with\nthe Error object (if any) passed as the first argument. If no error was raised,\nthe first argument will be passed as <code>null</code>.</p>\n<pre><code class=\"lang-js\">const fs = require(&#39;fs&#39;);\n\nfunction nodeStyleCallback(err, data) {\n  if (err) {\n    console.error(&#39;There was an error&#39;, err);\n    return;\n  }\n  console.log(data);\n}\n\nfs.readFile(&#39;/some/file/that/does-not-exist&#39;, nodeStyleCallback);\nfs.readFile(&#39;/some/file/that/does-exist&#39;, nodeStyleCallback);\n</code></pre>\n<p>The JavaScript <code>try / catch</code> mechanism <strong>cannot</strong> be used to intercept errors\ngenerated by asynchronous APIs. A common mistake for beginners is to try to\nuse <code>throw</code> inside a Node.js style callback:</p>\n<pre><code class=\"lang-js\">// THIS WILL NOT WORK:\nconst fs = require(&#39;fs&#39;);\n\ntry {\n  fs.readFile(&#39;/some/file/that/does-not-exist&#39;, (err, data) =&gt; {\n    // mistaken assumption: throwing here...\n    if (err) {\n      throw err;\n    }\n  });\n} catch (err) {\n  // This will not catch the throw!\n  console.error(err);\n}\n</code></pre>\n<p>This will not work because the callback function passed to <code>fs.readFile()</code> is\ncalled asynchronously. By the time the callback has been called, the\nsurrounding code (including the <code>try { } catch (err) { }</code> block will have\nalready exited. Throwing an error inside the callback <strong>can crash the Node.js\nprocess</strong> in most cases. If <a href=\"domain.html\">domains</a> are enabled, or a handler has been\nregistered with <code>process.on(&#39;uncaughtException&#39;)</code>, such errors can be\nintercepted.</p>\n"
            }
          ]
        },
        {
          "textRaw": "Exceptions vs. Errors",
          "name": "Exceptions vs. Errors",
          "type": "misc",
          "desc": "<p>A JavaScript exception is a value that is thrown as a result of an invalid\noperation or as the target of a <code>throw</code> statement. While it is not required\nthat these values are instances of <code>Error</code> or classes which inherit from\n<code>Error</code>, all exceptions thrown by Node.js or the JavaScript runtime <em>will</em> be\ninstances of Error.</p>\n<p>Some exceptions are <em>unrecoverable</em> at the JavaScript layer. Such exceptions\nwill <em>always</em> cause the Node.js process to crash. Examples include <code>assert()</code>\nchecks or <code>abort()</code> calls in the C++ layer.</p>\n"
        },
        {
          "textRaw": "System Errors",
          "name": "system_errors",
          "desc": "<p>System errors are generated when exceptions occur within the program&#39;s\nruntime environment. Typically, these are operational errors that occur\nwhen an application violates an operating system constraint such as attempting\nto read a file that does not exist or when the user does not have sufficient\npermissions.</p>\n<p>System errors are typically generated at the syscall level: an exhaustive list\nof error codes and their meanings is available by running <code>man 2 intro</code> or\n<code>man 3 errno</code> on most Unices; or <a href=\"http://man7.org/linux/man-pages/man3/errno.3.html\">online</a>.</p>\n<p>In Node.js, system errors are represented as augmented <code>Error</code> objects with\nadded properties.</p>\n",
          "classes": [
            {
              "textRaw": "Class: System Error",
              "type": "class",
              "name": "System",
              "properties": [
                {
                  "textRaw": "`code` {string} ",
                  "type": "string",
                  "name": "code",
                  "desc": "<p>The <code>error.code</code> property is a string representing the error code, which is always\n<code>E</code> followed by a sequence of capital letters.</p>\n"
                },
                {
                  "textRaw": "`errno` {string|number} ",
                  "type": "string|number",
                  "name": "errno",
                  "desc": "<p>The <code>error.errno</code> property is a number or a string.\nThe number is a <strong>negative</strong> value which corresponds to the error code defined in\n<a href=\"http://docs.libuv.org/en/v1.x/errors.html\"><code>libuv Error handling</code></a>. See uv-errno.h header file (<code>deps/uv/include/uv-errno.h</code> in\nthe Node.js source tree) for details.\nIn case of a string, it is the same as <code>error.code</code>.</p>\n"
                },
                {
                  "textRaw": "`syscall` {string} ",
                  "type": "string",
                  "name": "syscall",
                  "desc": "<p>The <code>error.syscall</code> property is a string describing the <a href=\"http://man7.org/linux/man-pages/man2/syscall.2.html\">syscall</a> that failed.</p>\n"
                },
                {
                  "textRaw": "`path` {string} ",
                  "type": "string",
                  "name": "path",
                  "desc": "<p>When present (e.g. in <code>fs</code> or <code>child_process</code>), the <code>error.path</code> property is a string\ncontaining a relevant invalid pathname.</p>\n"
                },
                {
                  "textRaw": "`address` {string} ",
                  "type": "string",
                  "name": "address",
                  "desc": "<p>When present (e.g. in <code>net</code> or <code>dgram</code>), the <code>error.address</code> property is a string\ndescribing the address to which the connection failed.</p>\n"
                },
                {
                  "textRaw": "`port` {number} ",
                  "type": "number",
                  "name": "port",
                  "desc": "<p>When present (e.g. in <code>net</code> or <code>dgram</code>), the <code>error.port</code> property is a number representing\nthe connection&#39;s port that is not available.</p>\n"
                }
              ]
            }
          ],
          "modules": [
            {
              "textRaw": "Common System Errors",
              "name": "common_system_errors",
              "desc": "<p>This list is <strong>not exhaustive</strong>, but enumerates many of the common system\nerrors encountered when writing a Node.js program. An exhaustive list may be\nfound <a href=\"http://man7.org/linux/man-pages/man3/errno.3.html\">here</a>.</p>\n<ul>\n<li><p><code>EACCES</code> (Permission denied): An attempt was made to access a file in a way\nforbidden by its file access permissions.</p>\n</li>\n<li><p><code>EADDRINUSE</code> (Address already in use): An attempt to bind a server\n(<a href=\"net.html\"><code>net</code></a>, <a href=\"http.html\"><code>http</code></a>, or <a href=\"https.html\"><code>https</code></a>) to a local address failed due to\nanother server on the local system already occupying that address.</p>\n</li>\n<li><p><code>ECONNREFUSED</code> (Connection refused): No connection could be made because the\ntarget machine actively refused it. This usually results from trying to\nconnect to a service that is inactive on the foreign host.</p>\n</li>\n<li><p><code>ECONNRESET</code> (Connection reset by peer): A connection was forcibly closed by\na peer. This normally results from a loss of the connection on the remote\nsocket due to a timeout or reboot. Commonly encountered via the <a href=\"http.html\"><code>http</code></a>\nand <a href=\"net.html\"><code>net</code></a> modules.</p>\n</li>\n<li><p><code>EEXIST</code> (File exists): An existing file was the target of an operation that\nrequired that the target not exist.</p>\n</li>\n<li><p><code>EISDIR</code> (Is a directory): An operation expected a file, but the given\npathname was a directory.</p>\n</li>\n<li><p><code>EMFILE</code> (Too many open files in system): Maximum number of\n<a href=\"https://en.wikipedia.org/wiki/File_descriptor\">file descriptors</a> allowable on the system has been reached, and\nrequests for another descriptor cannot be fulfilled until at least one\nhas been closed. This is encountered when opening many files at once in\nparallel, especially on systems (in particular, macOS) where there is a low\nfile descriptor limit for processes. To remedy a low limit, run\n<code>ulimit -n 2048</code> in the same shell that will run the Node.js process.</p>\n</li>\n<li><p><code>ENOENT</code> (No such file or directory): Commonly raised by <a href=\"fs.html\"><code>fs</code></a> operations\nto indicate that a component of the specified pathname does not exist — no\nentity (file or directory) could be found by the given path.</p>\n</li>\n<li><p><code>ENOTDIR</code> (Not a directory): A component of the given pathname existed, but\nwas not a directory as expected. Commonly raised by <a href=\"fs.html#fs_fs_readdir_path_options_callback\"><code>fs.readdir</code></a>.</p>\n</li>\n<li><p><code>ENOTEMPTY</code> (Directory not empty): A directory with entries was the target\nof an operation that requires an empty directory — usually <a href=\"fs.html#fs_fs_unlink_path_callback\"><code>fs.unlink</code></a>.</p>\n</li>\n<li><p><code>EPERM</code> (Operation not permitted): An attempt was made to perform an\noperation that requires elevated privileges.</p>\n</li>\n<li><p><code>EPIPE</code> (Broken pipe): A write on a pipe, socket, or FIFO for which there is\nno process to read the data. Commonly encountered at the <a href=\"net.html\"><code>net</code></a> and\n<a href=\"http.html\"><code>http</code></a> layers, indicative that the remote side of the stream being\nwritten to has been closed.</p>\n</li>\n<li><p><code>ETIMEDOUT</code> (Operation timed out): A connect or send request failed because\nthe connected party did not properly respond after a period of time. Usually\nencountered by <a href=\"http.html\"><code>http</code></a> or <a href=\"net.html\"><code>net</code></a> — often a sign that a <code>socket.end()</code>\nwas not properly called.</p>\n</li>\n</ul>\n",
              "type": "module",
              "displayName": "Common System Errors"
            }
          ],
          "type": "misc",
          "displayName": "System Errors"
        }
      ],
      "classes": [
        {
          "textRaw": "Class: Error",
          "type": "class",
          "name": "Error",
          "desc": "<p>A generic JavaScript <code>Error</code> object that does not denote any specific\ncircumstance of why the error occurred. <code>Error</code> objects capture a &quot;stack trace&quot;\ndetailing the point in the code at which the <code>Error</code> was instantiated, and may\nprovide a text description of the error.</p>\n<p>All errors generated by Node.js, including all System and JavaScript errors,\nwill either be instances of, or inherit from, the <code>Error</code> class.</p>\n",
          "methods": [
            {
              "textRaw": "Error.captureStackTrace(targetObject[, constructorOpt])",
              "type": "method",
              "name": "captureStackTrace",
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`targetObject` {Object} ",
                      "name": "targetObject",
                      "type": "Object"
                    },
                    {
                      "textRaw": "`constructorOpt` {Function} ",
                      "name": "constructorOpt",
                      "type": "Function",
                      "optional": true
                    }
                  ]
                },
                {
                  "params": [
                    {
                      "name": "targetObject"
                    },
                    {
                      "name": "constructorOpt",
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>Creates a <code>.stack</code> property on <code>targetObject</code>, which when accessed returns\na string representing the location in the code at which\n<code>Error.captureStackTrace()</code> was called.</p>\n<pre><code class=\"lang-js\">const myObject = {};\nError.captureStackTrace(myObject);\nmyObject.stack;  // similar to `new Error().stack`\n</code></pre>\n<p>The first line of the trace, instead of being prefixed with <code>ErrorType:\nmessage</code>, will be the result of calling <code>targetObject.toString()</code>.</p>\n<p>The optional <code>constructorOpt</code> argument accepts a function. If given, all frames\nabove <code>constructorOpt</code>, including <code>constructorOpt</code>, will be omitted from the\ngenerated stack trace.</p>\n<p>The <code>constructorOpt</code> argument is useful for hiding implementation\ndetails of error generation from an end user. For instance:</p>\n<pre><code class=\"lang-js\">function MyError() {\n  Error.captureStackTrace(this, MyError);\n}\n\n// Without passing MyError to captureStackTrace, the MyError\n// frame would show up in the .stack property. By passing\n// the constructor, we omit that frame, and retain all frames below it.\nnew MyError().stack;\n</code></pre>\n"
            }
          ],
          "properties": [
            {
              "textRaw": "`stackTraceLimit` {number} ",
              "type": "number",
              "name": "stackTraceLimit",
              "desc": "<p>The <code>Error.stackTraceLimit</code> property specifies the number of stack frames\ncollected by a stack trace (whether generated by <code>new Error().stack</code> or\n<code>Error.captureStackTrace(obj)</code>).</p>\n<p>The default value is <code>10</code> but may be set to any valid JavaScript number. Changes\nwill affect any stack trace captured <em>after</em> the value has been changed.</p>\n<p>If set to a non-number value, or set to a negative number, stack traces will\nnot capture any frames.</p>\n"
            },
            {
              "textRaw": "`message` {string} ",
              "type": "string",
              "name": "message",
              "desc": "<p>The <code>error.message</code> property is the string description of the error as set by calling <code>new Error(message)</code>.\nThe <code>message</code> passed to the constructor will also appear in the first line of\nthe stack trace of the <code>Error</code>, however changing this property after the\n<code>Error</code> object is created <em>may not</em> change the first line of the stack trace\n(for example, when <code>error.stack</code> is read before this property is changed).</p>\n<pre><code class=\"lang-js\">const err = new Error(&#39;The message&#39;);\nconsole.error(err.message);\n// Prints: The message\n</code></pre>\n"
            },
            {
              "textRaw": "`stack` {string} ",
              "type": "string",
              "name": "stack",
              "desc": "<p>The <code>error.stack</code> property is a string describing the point in the code at which\nthe <code>Error</code> was instantiated.</p>\n<p>For example:</p>\n<pre><code class=\"lang-txt\">Error: Things keep happening!\n   at /home/gbusey/file.js:525:2\n   at Frobnicator.refrobulate (/home/gbusey/business-logic.js:424:21)\n   at Actor.&lt;anonymous&gt; (/home/gbusey/actors.js:400:8)\n   at increaseSynergy (/home/gbusey/actors.js:701:6)\n</code></pre>\n<p>The first line is formatted as <code>&lt;error class name&gt;: &lt;error message&gt;</code>, and\nis followed by a series of stack frames (each line beginning with &quot;at &quot;).\nEach frame describes a call site within the code that lead to the error being\ngenerated. V8 attempts to display a name for each function (by variable name,\nfunction name, or object method name), but occasionally it will not be able to\nfind a suitable name. If V8 cannot determine a name for the function, only\nlocation information will be displayed for that frame. Otherwise, the\ndetermined function name will be displayed with location information appended\nin parentheses.</p>\n<p>It is important to note that frames are <strong>only</strong> generated for JavaScript\nfunctions. If, for example, execution synchronously passes through a C++ addon\nfunction called <code>cheetahify</code>, which itself calls a JavaScript function, the\nframe representing the <code>cheetahify</code> call will <strong>not</strong> be present in the stack\ntraces:</p>\n<pre><code class=\"lang-js\">const cheetahify = require(&#39;./native-binding.node&#39;);\n\nfunction makeFaster() {\n  // cheetahify *synchronously* calls speedy.\n  cheetahify(function speedy() {\n    throw new Error(&#39;oh no!&#39;);\n  });\n}\n\nmakeFaster(); // will throw:\n// /home/gbusey/file.js:6\n//     throw new Error(&#39;oh no!&#39;);\n//           ^\n// Error: oh no!\n//     at speedy (/home/gbusey/file.js:6:11)\n//     at makeFaster (/home/gbusey/file.js:5:3)\n//     at Object.&lt;anonymous&gt; (/home/gbusey/file.js:10:1)\n//     at Module._compile (module.js:456:26)\n//     at Object.Module._extensions..js (module.js:474:10)\n//     at Module.load (module.js:356:32)\n//     at Function.Module._load (module.js:312:12)\n//     at Function.Module.runMain (module.js:497:10)\n//     at startup (node.js:119:16)\n//     at node.js:906:3\n</code></pre>\n<p>The location information will be one of:</p>\n<ul>\n<li><code>native</code>, if the frame represents a call internal to V8 (as in <code>[].forEach</code>).</li>\n<li><code>plain-filename.js:line:column</code>, if the frame represents a call internal\n to Node.js.</li>\n<li><code>/absolute/path/to/file.js:line:column</code>, if the frame represents a call in\na user program, or its dependencies.</li>\n</ul>\n<p>The string representing the stack trace is lazily generated when the\n<code>error.stack</code> property is <strong>accessed</strong>.</p>\n<p>The number of frames captured by the stack trace is bounded by the smaller of\n<code>Error.stackTraceLimit</code> or the number of available frames on the current event\nloop tick.</p>\n<p>System-level errors are generated as augmented <code>Error</code> instances, which are\ndetailed <a href=\"#errors_system_errors\">here</a>.</p>\n"
            }
          ],
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`message` {string} ",
                  "name": "message",
                  "type": "string"
                }
              ],
              "desc": "<p>Creates a new <code>Error</code> object and sets the <code>error.message</code> property to the\nprovided text message. If an object is passed as <code>message</code>, the text message\nis generated by calling <code>message.toString()</code>. The <code>error.stack</code> property will\nrepresent the point in the code at which <code>new Error()</code> was called. Stack traces\nare dependent on <a href=\"https://github.com/v8/v8/wiki/Stack-Trace-API\">V8&#39;s stack trace API</a>. Stack traces extend only to either\n(a) the beginning of <em>synchronous code execution</em>, or (b) the number of frames\ngiven by the property <code>Error.stackTraceLimit</code>, whichever is smaller.</p>\n"
            },
            {
              "params": [
                {
                  "name": "message"
                }
              ],
              "desc": "<p>Creates a new <code>Error</code> object and sets the <code>error.message</code> property to the\nprovided text message. If an object is passed as <code>message</code>, the text message\nis generated by calling <code>message.toString()</code>. The <code>error.stack</code> property will\nrepresent the point in the code at which <code>new Error()</code> was called. Stack traces\nare dependent on <a href=\"https://github.com/v8/v8/wiki/Stack-Trace-API\">V8&#39;s stack trace API</a>. Stack traces extend only to either\n(a) the beginning of <em>synchronous code execution</em>, or (b) the number of frames\ngiven by the property <code>Error.stackTraceLimit</code>, whichever is smaller.</p>\n"
            }
          ]
        },
        {
          "textRaw": "Class: RangeError",
          "type": "class",
          "name": "RangeError",
          "desc": "<p>A subclass of <code>Error</code> that indicates that a provided argument was not within the\nset or range of acceptable values for a function; whether that is a numeric\nrange, or outside the set of options for a given function parameter.</p>\n<p>For example:</p>\n<pre><code class=\"lang-js\">require(&#39;net&#39;).connect(-1);\n// throws &quot;RangeError: &quot;port&quot; option should be &gt;= 0 and &lt; 65536: -1&quot;\n</code></pre>\n<p>Node.js will generate and throw <code>RangeError</code> instances <em>immediately</em> as a form\nof argument validation.</p>\n"
        },
        {
          "textRaw": "Class: ReferenceError",
          "type": "class",
          "name": "ReferenceError",
          "desc": "<p>A subclass of <code>Error</code> that indicates that an attempt is being made to access a\nvariable that is not defined. Such errors commonly indicate typos in code, or\nan otherwise broken program.</p>\n<p>While client code may generate and propagate these errors, in practice, only V8\nwill do so.</p>\n<pre><code class=\"lang-js\">doesNotExist;\n// throws ReferenceError, doesNotExist is not a variable in this program.\n</code></pre>\n<p>Unless an application is dynamically generating and running code,\n<code>ReferenceError</code> instances should always be considered a bug in the code\nor its dependencies.</p>\n"
        },
        {
          "textRaw": "Class: SyntaxError",
          "type": "class",
          "name": "SyntaxError",
          "desc": "<p>A subclass of <code>Error</code> that indicates that a program is not valid JavaScript.\nThese errors may only be generated and propagated as a result of code\nevaluation. Code evaluation may happen as a result of <code>eval</code>, <code>Function</code>,\n<code>require</code>, or <a href=\"vm.html\">vm</a>. These errors are almost always indicative of a broken\nprogram.</p>\n<pre><code class=\"lang-js\">try {\n  require(&#39;vm&#39;).runInThisContext(&#39;binary ! isNotOk&#39;);\n} catch (err) {\n  // err will be a SyntaxError\n}\n</code></pre>\n<p><code>SyntaxError</code> instances are unrecoverable in the context that created them –\nthey may only be caught by other contexts.</p>\n"
        },
        {
          "textRaw": "Class: TypeError",
          "type": "class",
          "name": "TypeError",
          "desc": "<p>A subclass of <code>Error</code> that indicates that a provided argument is not an\nallowable type. For example, passing a function to a parameter which expects a\nstring would be considered a TypeError.</p>\n<pre><code class=\"lang-js\">require(&#39;url&#39;).parse(() =&gt; { });\n// throws TypeError, since it expected a string\n</code></pre>\n<p>Node.js will generate and throw <code>TypeError</code> instances <em>immediately</em> as a form\nof argument validation.</p>\n"
        }
      ]
    }
  ]
}