summaryrefslogtreecommitdiff
path: root/lib/tty.js
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-03-21 00:46:30 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-04-05 04:46:26 +0800
commit7d06761f839bbff8c671b0e1a6d541faa5452354 (patch)
tree0e7b375cd841c9a66f8c08cffe4b03d2f6c60277 /lib/tty.js
parent3e0d40d4af6f437ecacb8b54d0d84ed0e5a4899f (diff)
downloadandroid-node-v8-7d06761f839bbff8c671b0e1a6d541faa5452354.tar.gz
android-node-v8-7d06761f839bbff8c671b0e1a6d541faa5452354.tar.bz2
android-node-v8-7d06761f839bbff8c671b0e1a6d541faa5452354.zip
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>
Diffstat (limited to 'lib/tty.js')
-rw-r--r--lib/tty.js6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/tty.js b/lib/tty.js
index dfb76bbe53..4e9023b0eb 100644
--- a/lib/tty.js
+++ b/lib/tty.js
@@ -25,7 +25,7 @@ const { inherits, _extend } = require('util');
const net = require('net');
const { TTY, isTTY } = process.binding('tty_wrap');
const errors = require('internal/errors');
-const { ERR_INVALID_FD } = errors.codes;
+const { ERR_INVALID_FD, ERR_TTY_INIT_FAILED } = errors.codes;
const readline = require('readline');
const { getColorDepth } = require('internal/tty');
@@ -42,7 +42,7 @@ function ReadStream(fd, options) {
const ctx = {};
const tty = new TTY(fd, true, ctx);
if (ctx.code !== undefined) {
- throw new errors.SystemError(ctx);
+ throw new ERR_TTY_INIT_FAILED(ctx);
}
options = _extend({
@@ -74,7 +74,7 @@ function WriteStream(fd) {
const ctx = {};
const tty = new TTY(fd, false, ctx);
if (ctx.code !== undefined) {
- throw new errors.SystemError(ctx);
+ throw new ERR_TTY_INIT_FAILED(ctx);
}
net.Socket.call(this, {