Skip to content

Commit 59a1d00

Browse files
darai0512MylesBorins
authored andcommitted
doc: add and fix System Error properties
About path, address and port properties, these are not described though being also represented as augmented Error objects with added properties. And also, fix all property descriptions and add type annotations. PR-URL: #10986 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sam Roberts <[email protected]>
1 parent 72adba4 commit 59a1d00

File tree

1 file changed

+52
-10
lines changed

1 file changed

+52
-10
lines changed

doc/api/errors.md

+52-10
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ will either be instances of, or inherit from, the `Error` class.
195195

196196
### new Error(message)
197197

198+
* `message` {String}
199+
198200
Creates a new `Error` object and sets the `error.message` property to the
199201
provided text message. If an object is passed as `message`, the text message
200202
is generated by calling `message.toString()`. The `error.stack` property will
@@ -205,6 +207,9 @@ given by the property `Error.stackTraceLimit`, whichever is smaller.
205207

206208
### Error.captureStackTrace(targetObject[, constructorOpt])
207209

210+
* `targetObject` {Object}
211+
* `constructorOpt` {Function}
212+
208213
Creates a `.stack` property on `targetObject`, which when accessed returns
209214
a string representing the location in the code at which
210215
`Error.captureStackTrace()` was called.
@@ -238,6 +243,8 @@ new MyError().stack
238243

239244
### Error.stackTraceLimit
240245

246+
* {Number}
247+
241248
The `Error.stackTraceLimit` property specifies the number of stack frames
242249
collected by a stack trace (whether generated by `new Error().stack` or
243250
`Error.captureStackTrace(obj)`).
@@ -250,10 +257,13 @@ not capture any frames.
250257

251258
#### error.message
252259

253-
Returns the string description of error as set by calling `new Error(message)`.
260+
* {String}
261+
262+
The `error.message` property is the string description of the error as set by calling `new Error(message)`.
254263
The `message` passed to the constructor will also appear in the first line of
255264
the stack trace of the `Error`, however changing this property after the
256-
`Error` object is created *may not* change the first line of the stack trace.
265+
`Error` object is created *may not* change the first line of the stack trace
266+
(for example, when `error.stack` is read before this property is changed).
257267

258268
```js
259269
const err = new Error('The message');
@@ -263,8 +273,10 @@ console.log(err.message);
263273

264274
#### error.stack
265275

266-
Returns a string describing the point in the code at which the `Error` was
267-
instantiated.
276+
* {String}
277+
278+
The `error.stack` property is a string describing the point in the code at which
279+
the `Error` was instantiated.
268280

269281
For example:
270282

@@ -450,18 +462,47 @@ added properties.
450462

451463
#### error.code
452464

453-
Returns a string representing the error code, which is always `E` followed by
454-
a sequence of capital letters, and may be referenced in `man 2 intro`.
465+
* {String}
466+
467+
The `error.code` property is a string representing the error code, which is always
468+
`E` followed by a sequence of capital letters.
455469

456470
#### error.errno
457471

458-
Returns a number corresponding to the **negated** error code, which may be
459-
referenced in `man 2 intro`. For example, an `ENOENT` error has an `errno` of
460-
`-2` because the error code for `ENOENT` is `2`.
472+
* {String | Number}
473+
474+
The `error.errno` property is a number or a string.
475+
The number is a **negative** value which corresponds to the error code defined in
476+
[`libuv Error handling`]. See uv-errno.h header file (`deps/uv/include/uv-errno.h` in
477+
the Node.js source tree) for details.
478+
In case of a string, it is the same as `error.code`.
461479

462480
#### error.syscall
463481

464-
Returns a string describing the [syscall][] that failed.
482+
* {String}
483+
484+
The `error.syscall` property is a string describing the [syscall][] that failed.
485+
486+
#### error.path
487+
488+
* {String}
489+
490+
When present (e.g. in `fs` or `child_process`), the `error.path` property is a string
491+
containing a relevant invalid pathname.
492+
493+
#### error.address
494+
495+
* {String}
496+
497+
When present (e.g. in `net` or `dgram`), the `error.address` property is a string
498+
describing the address to which the connection failed.
499+
500+
#### error.port
501+
502+
* {Number}
503+
504+
When present (e.g. in `net` or `dgram`), the `error.port` property is a number representing
505+
the connection's port that is not available.
465506

466507
### Common System Errors
467508

@@ -528,6 +569,7 @@ found [here][online].
528569
[`fs`]: fs.html
529570
[`http`]: http.html
530571
[`https`]: https.html
572+
[`libuv Error handling`]: http://docs.libuv.org/en/v1.x/errors.html
531573
[`net`]: net.html
532574
[`process.on('uncaughtException')`]: process.html#process_event_uncaughtexception
533575
[domains]: domain.html

0 commit comments

Comments
 (0)