node/lib/internal
Joyee Cheung 7d06761f83
errors: improve SystemError messages
This commit improves the SystemError messages by allowing user
to combine a custom message and the libuv error message. Also
since we now prefer use subclasses to construct the errors instead
of using `new errors.SystemError()` directly, this removes
the behavior of assigning a default error code `ERR_SYSTEM_ERROR`
to SystemError and requires the user to directly use the
`ERR_SYSTEM_ERROR` class to construct errors instead.

Also merges `makeNodeError` into the SystemError class definition
since that's the only place the function gets used and it seems
unnecessary to introduce another level of inheritance. SystemError
now directly inherits from Error instead of an intermmediate Error
class that inherits from Error.

Class hierarchy before this patch:

ERR_SOCKET_BUFFER_SIZE -> Error (use message formatted by SystemError)
ERR_SYSTEM_ERROR -> NodeError (temp) -> Error

After:

ERR_SOCKET_BUFFER_SIZE -> SystemError -> Error
ERR_TTY_INIT_FAILED -> SystemError -> Error
ERR_SYSTEM_ERROR -> SystemError -> Error

Error messages before this patch:

```
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
socket.setRecvBufferSize(8192);

// Error [ERR_SOCKET_BUFFER_SIZE]: Could not get or set buffer
// size: Error [ERR_SYSTEM_ERROR]: bad file descriptor:
// EBADF [uv_recv_buffer_size]
//    at bufferSize (dgram.js:191:11)
//    at Socket.setRecvBufferSize (dgram.js:689:3)

const tty = require('tty');
new tty.WriteStream(1 << 30);
// Error [ERR_SYSTEM_ERROR]: invalid argument: EINVAL [uv_tty_init]
//     at new WriteStream (tty.js:84:11)
```

After:

```
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
socket.setRecvBufferSize(8192);

// SystemError [ERR_SOCKET_BUFFER_SIZE]: Could not get or set buffer
// size: uv_recv_buffer_size returned EBADF (bad file descriptor)
//     at bufferSize (dgram.js:191:11)
//     at Socket.setRecvBufferSize (dgram.js:689:3)

const tty = require('tty');
new tty.WriteStream(1 << 30);
// SystemError [ERR_TTY_INIT_FAILED]: TTY initialization failed:
// uv_tty_init returned EINVAL (invalid argument)
//     at new WriteStream (tty.js:84:11)
```

PR-URL: https://github.com/nodejs/node/pull/19514
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-04-05 04:46:26 +08:00
..
bootstrap vm: move options checks from C++ to JS 2018-04-03 17:59:22 +02:00
cluster cluster: add support for NODE_OPTIONS="--inspect" 2018-03-21 15:27:54 -04:00
crypto crypto: fix error handling 2018-03-25 01:45:39 +01:00
http2 lib: merge stream code for http2 streams & net.Socket 2018-03-27 12:57:23 +02:00
modules module: skip preserveSymlinks for main 2018-04-01 17:32:26 +02:00
process vm: add support for import.meta to Module 2018-03-31 19:55:50 -05:00
repl repl: support top-level await 2017-11-16 15:42:46 -08:00
streams lib: rename js source to lower snake_case 2018-03-28 08:09:16 +02:00
test src: put bootstrappers in lib/internal/bootstrap/ 2018-03-15 20:50:34 +08:00
util src: put bootstrappers in lib/internal/bootstrap/ 2018-03-15 20:50:34 +08:00
vm vm: move options checks from C++ to JS 2018-04-03 17:59:22 +02:00
async_hooks.js async_hooks: add copyHooks function 2018-03-20 07:42:00 +01:00
buffer.js buffer: improve write(U)Int functions 2018-03-24 16:50:01 +01:00
child_process.js child_process: define EACCES as a runtime error 2018-03-15 20:47:45 +05:30
cli_table.js console: add table method 2018-03-30 19:41:41 -05:00
constants.js url: replace "magic" numbers by constants 2018-03-11 03:45:50 +01:00
encoding.js lib: always show ERR_INVALID_ARG_TYPE received part 2018-03-25 01:45:37 +01:00
errors.js errors: improve SystemError messages 2018-04-05 04:46:26 +08:00
freelist.js lib: update indentation of ternaries 2017-07-17 22:09:46 -07:00
fs.js fs: refactor stats array to be more generic 2018-04-04 15:25:59 +08:00
http.js http: convert utcDate to use setTimeout 2017-12-29 00:08:54 +01:00
inspector_async_hook.js inspector: no async tracking for promises 2017-11-21 13:57:05 +01:00
linkedlist.js linkedlist: correct grammar in comments 2017-07-31 08:03:19 +08:00
net.js net: track bytesWritten in C++ land 2018-03-30 14:20:40 +02:00
os.js os: add CIDR support 2017-08-14 15:43:10 -04:00
process.js Revert "process: add more version properties to release" 2018-03-25 03:18:56 +02:00
querystring.js lib: use Object.create(null) directly 2017-03-24 15:25:49 -07:00
readline.js lib,test: lint fixes for linter upgrade 2018-03-24 04:11:40 -07:00
readme.md doc: limit lines to 80 cols in internal README 2017-04-13 15:30:10 -07:00
repl.js lib: switch to Number.isNaN 2018-02-16 18:09:56 +01:00
safe_globals.js module: Allow runMain to be ESM 2017-09-07 15:18:32 -05:00
socket_list.js lib: port remaining errors to new system 2018-03-07 14:54:38 +01:00
stream_base_commons.js lib: merge stream code for http2 streams & net.Socket 2018-03-27 12:57:23 +02:00
timers.js lib: port remaining errors to new system 2018-03-07 14:54:38 +01:00
tls.js tls: deprecate parseCertString & move to internal 2017-09-13 16:54:35 -03:00
trace_events_async_hooks.js src: add tracing category macros 2018-03-09 08:09:41 -08:00
tty.js tty: add color support for more terminals 2018-04-04 15:14:05 +02:00
url.js tools: add 'spaced-comment' into eslint rules 2018-04-01 22:33:13 +08:00
util.js lib: always show ERR_INVALID_ARG_TYPE received part 2018-03-25 01:45:37 +01:00
v8.js util: show Weak(Set|Map) entries in inspect 2018-03-25 03:21:27 +02:00
v8_prof_polyfill.js tools, test: fix prof polyfill readline 2018-02-17 10:06:53 -02:00
v8_prof_processor.js lib: define printErr() in script string 2018-03-12 08:45:13 -07:00
wrap_js_stream.js lib: port remaining errors to new system 2018-03-07 14:54:38 +01:00

readme.md

Internal Modules

The modules in lib/internal are intended for internal use in Node.js core only, and are not accessible with require() from user modules. These are subject to change at any time. Reliance on these modules outside of core is not supported in any way.