From 1a452f1928c3c904f8405048794632a6da6a94c6 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 21 Jun 2017 20:23:37 +0200 Subject: [PATCH] dgram,process,util: refactor Error to TypeError PR-URL: https://github.com/nodejs/node/pull/13857 Reviewed-By: Refael Ackermann Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Michael Dawson --- lib/dgram.js | 2 +- lib/internal/process.js | 2 +- lib/internal/util.js | 2 +- test/parallel/test-child-process-constructor.js | 2 +- test/parallel/test-child-process-spawnsync-kill-signal.js | 2 +- test/parallel/test-child-process-spawnsync-validation-errors.js | 2 +- test/parallel/test-dgram-createSocket-type.js | 2 +- test/parallel/test-process-kill-pid.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/dgram.js b/lib/dgram.js index 55753b177279a9..3204ad87cd5cd9 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -79,7 +79,7 @@ function newHandle(type) { return handle; } - throw new errors.Error('ERR_SOCKET_BAD_TYPE'); + throw new errors.TypeError('ERR_SOCKET_BAD_TYPE'); } diff --git a/lib/internal/process.js b/lib/internal/process.js index 062b16e09039a6..bb9117ea09de50 100644 --- a/lib/internal/process.js +++ b/lib/internal/process.js @@ -181,7 +181,7 @@ function setupKillAndExit() { if (lazyConstants()[sig]) { err = process._kill(pid, lazyConstants()[sig]); } else { - throw new errors.Error('ERR_UNKNOWN_SIGNAL', `${sig}`); + throw new errors.TypeError('ERR_UNKNOWN_SIGNAL', sig); } } diff --git a/lib/internal/util.js b/lib/internal/util.js index efdd7e0fd277b3..543ebbaf6d6fa6 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -180,7 +180,7 @@ function convertToValidSignal(signal) { if (signalName) return signalName; } - throw new errors.Error('ERR_UNKNOWN_SIGNAL', signal); + throw new errors.TypeError('ERR_UNKNOWN_SIGNAL', signal); } function getConstructorOf(obj) { diff --git a/test/parallel/test-child-process-constructor.js b/test/parallel/test-child-process-constructor.js index 8e62f5cc238c22..54052d9f7140dd 100644 --- a/test/parallel/test-child-process-constructor.js +++ b/test/parallel/test-child-process-constructor.js @@ -68,6 +68,6 @@ assert(Number.isInteger(child.pid)); // try killing with invalid signal assert.throws(() => { child.kill('foo'); -}, common.expectsError({ code: 'ERR_UNKNOWN_SIGNAL' })); +}, common.expectsError({ code: 'ERR_UNKNOWN_SIGNAL', type: TypeError })); assert.strictEqual(child.kill(), true); diff --git a/test/parallel/test-child-process-spawnsync-kill-signal.js b/test/parallel/test-child-process-spawnsync-kill-signal.js index f199d288a1ab0c..90d6225223e635 100644 --- a/test/parallel/test-child-process-spawnsync-kill-signal.js +++ b/test/parallel/test-child-process-spawnsync-kill-signal.js @@ -31,7 +31,7 @@ if (process.argv[2] === 'child') { // Verify that an error is thrown for unknown signals. assert.throws(() => { spawn('SIG_NOT_A_REAL_SIGNAL'); - }, common.expectsError({ code: 'ERR_UNKNOWN_SIGNAL' })); + }, common.expectsError({ code: 'ERR_UNKNOWN_SIGNAL', type: TypeError })); // Verify that the default kill signal is SIGTERM. { diff --git a/test/parallel/test-child-process-spawnsync-validation-errors.js b/test/parallel/test-child-process-spawnsync-validation-errors.js index dab4b1d37d80f9..98a947825f297b 100644 --- a/test/parallel/test-child-process-spawnsync-validation-errors.js +++ b/test/parallel/test-child-process-spawnsync-validation-errors.js @@ -186,7 +186,7 @@ if (!common.isWindows) { // Validate the killSignal option const typeErr = /^TypeError: "killSignal" must be a string or number$/; const unknownSignalErr = - common.expectsError({ code: 'ERR_UNKNOWN_SIGNAL' }); + common.expectsError({ code: 'ERR_UNKNOWN_SIGNAL', type: TypeError }); pass('killSignal', undefined); pass('killSignal', null); diff --git a/test/parallel/test-dgram-createSocket-type.js b/test/parallel/test-dgram-createSocket-type.js index 125a9d0be5cc1c..96e3d6c8673d16 100644 --- a/test/parallel/test-dgram-createSocket-type.js +++ b/test/parallel/test-dgram-createSocket-type.js @@ -27,7 +27,7 @@ invalidTypes.forEach((invalidType) => { dgram.createSocket(invalidType); }, common.expectsError({ code: 'ERR_SOCKET_BAD_TYPE', - type: Error, + type: TypeError, message: errMessage })); }); diff --git a/test/parallel/test-process-kill-pid.js b/test/parallel/test-process-kill-pid.js index bf6f552fb07f04..74491710d2646b 100644 --- a/test/parallel/test-process-kill-pid.js +++ b/test/parallel/test-process-kill-pid.js @@ -60,7 +60,7 @@ assert.throws(function() { process.kill(-1 / 0); }, // Test that kill throws an error for invalid signal const unknownSignal = common.expectsError({ code: 'ERR_UNKNOWN_SIGNAL', - type: Error, + type: TypeError, message: 'Unknown signal: test' });