From 1832743e181149c16ccd3752247f4306d3aa0fe1 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Tue, 24 Mar 2015 15:15:57 +0100 Subject: [PATCH] lib: add missing `new` for errors lib/*.js Not including `new` adds a useless frame and removes a potentially useful frame. PR-URL: https://github.com/iojs/io.js/pull/1246 Reviewed-By: Petka Antonov Reviewed-By: Roman Reiss Reviewed-By: Brendan Ashworth --- lib/child_process.js | 4 ++-- lib/crypto.js | 2 +- lib/dns.js | 5 +++-- lib/events.js | 2 +- lib/fs.js | 6 +++--- lib/punycode.js | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 5fcd260..a38de28 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -860,9 +860,9 @@ function _validateStdio(stdio, sync) { // Cleanup previously created pipes cleanup(); if (!sync) - throw Error('Child process can have only one IPC pipe'); + throw new Error('Child process can have only one IPC pipe'); else - throw Error('You cannot use IPC with synchronous forks'); + throw new Error('You cannot use IPC with synchronous forks'); } ipc = createPipe(true); diff --git a/lib/crypto.js b/lib/crypto.js index 6033a85..10ff71e 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -548,7 +548,7 @@ ECDH.prototype.getPublicKey = function getPublicKey(encoding, format) { else if (format === 'uncompressed') f = constants.POINT_CONVERSION_UNCOMPRESSED; else - throw TypeError('Bad format: ' + format); + throw new TypeError('Bad format: ' + format); } else { f = constants.POINT_CONVERSION_UNCOMPRESSED; } diff --git a/lib/dns.js b/lib/dns.js index 4572d25..d39eec8 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -108,12 +108,13 @@ exports.lookup = function lookup(hostname, options, callback) { // Parse arguments if (hostname && typeof hostname !== 'string') { - throw TypeError('invalid arguments: hostname must be a string or falsey'); + throw new TypeError('invalid arguments: ' + + 'hostname must be a string or falsey'); } else if (typeof options === 'function') { callback = options; family = 0; } else if (typeof callback !== 'function') { - throw TypeError('invalid arguments: callback must be passed'); + throw new TypeError('invalid arguments: callback must be passed'); } else if (options !== null && typeof options === 'object') { hints = options.hints >>> 0; family = options.family >>> 0; diff --git a/lib/events.js b/lib/events.js index 6bd2a77..064f383 100644 --- a/lib/events.js +++ b/lib/events.js @@ -140,7 +140,7 @@ EventEmitter.prototype.emit = function emit(type) { } else if (er instanceof Error) { throw er; // Unhandled 'error' event } else { - throw Error('Uncaught, unspecified "error" event.'); + throw new Error('Uncaught, unspecified "error" event.'); } return false; } diff --git a/lib/fs.js b/lib/fs.js index adcb708..77bcbac 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1628,12 +1628,12 @@ function ReadStream(path, options) { if (this.start !== undefined) { if (typeof this.start !== 'number') { - throw TypeError('start must be a Number'); + throw new TypeError('start must be a Number'); } if (this.end === undefined) { this.end = Infinity; } else if (typeof this.end !== 'number') { - throw TypeError('end must be a Number'); + throw new TypeError('end must be a Number'); } if (this.start > this.end) { @@ -1790,7 +1790,7 @@ function WriteStream(path, options) { if (this.start !== undefined) { if (typeof this.start !== 'number') { - throw TypeError('start must be a Number'); + throw new TypeError('start must be a Number'); } if (this.start < 0) { throw new Error('start must be >= zero'); diff --git a/lib/punycode.js b/lib/punycode.js index 82cc207..51aa751 100644 --- a/lib/punycode.js +++ b/lib/punycode.js @@ -64,7 +64,7 @@ * @returns {Error} Throws a `RangeError` with the applicable error message. */ function error(type) { - throw RangeError(errors[type]); + throw new RangeError(errors[type]); } /** -- 2.7.4