summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2013-07-16 23:28:38 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2013-07-20 12:04:35 +0200
commit0161ec87af3d71b10d8ce679c8a1a64358fae8dc (patch)
treefda63e078b5729cdb8c17329a90dad8306b003d9 /lib
parentd4c14c1fe5402b8c3b1d582070ccbf3ae40f5b1f (diff)
downloadnode-0161ec87af3d71b10d8ce679c8a1a64358fae8dc.tar.gz
src, lib: deduplicate errnoException
Diffstat (limited to 'lib')
-rw-r--r--lib/child_process.js16
-rw-r--r--lib/dgram.js9
-rw-r--r--lib/dns.js25
-rw-r--r--lib/fs.js19
-rw-r--r--lib/net.js15
-rw-r--r--lib/tty.js12
-rw-r--r--lib/util.js12
7 files changed, 26 insertions, 82 deletions
diff --git a/lib/child_process.js b/lib/child_process.js
index d17329e38..b5b44bc37 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -28,6 +28,7 @@ var assert = require('assert');
var util = require('util');
var constants; // if (!constants) constants = process.binding('constants');
+var errnoException = util._errnoException;
var handleWraps = {};
function handleWrapGetter(name, callback) {
@@ -969,21 +970,6 @@ ChildProcess.prototype.spawn = function(options) {
};
-function errnoException(errorno, syscall, errmsg) {
- // TODO make this more compatible with ErrnoException from src/node.cc
- // Once all of Node is using this function the ErrnoException from
- // src/node.cc should be removed.
- var message = syscall + ' ' + errorno;
- if (errmsg) {
- message += ' - ' + errmsg;
- }
- var e = new Error(message);
- e.errno = e.code = errorno;
- e.syscall = syscall;
- return e;
-}
-
-
ChildProcess.prototype.kill = function(sig) {
var signal;
diff --git a/lib/dgram.js b/lib/dgram.js
index 7dd2086d7..570cbbe8d 100644
--- a/lib/dgram.js
+++ b/lib/dgram.js
@@ -34,6 +34,7 @@ var cluster = null;
var dns = null;
var net = null;
+var errnoException = util._errnoException;
// no-op callback
function noop() {
@@ -434,11 +435,3 @@ Socket.prototype.unref = function() {
if (this._handle)
this._handle.unref();
};
-
-// TODO share with net_uv and others
-function errnoException(errorno, syscall) {
- var e = new Error(syscall + ' ' + errorno);
- e.errno = e.code = errorno;
- e.syscall = syscall;
- return e;
-}
diff --git a/lib/dns.js b/lib/dns.js
index e9611a3a7..baac2b48d 100644
--- a/lib/dns.js
+++ b/lib/dns.js
@@ -19,27 +19,12 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-var cares = process.binding('cares_wrap'),
- net = require('net'),
- isIp = net.isIP;
+var cares = process.binding('cares_wrap');
+var net = require('net');
+var util = require('util');
-
-function errnoException(errorno, syscall) {
- // TODO make this more compatible with ErrnoException from src/node.cc
- // Once all of Node is using this function the ErrnoException from
- // src/node.cc should be removed.
-
- // For backwards compatibility. libuv returns ENOENT on NXDOMAIN.
- if (errorno == 'ENOENT') {
- errorno = 'ENOTFOUND';
- }
-
- var e = new Error(syscall + ' ' + errorno);
-
- e.errno = e.code = errorno;
- e.syscall = syscall;
- return e;
-}
+var errnoException = util._errnoException;
+var isIp = net.isIP;
// c-ares invokes a callback either synchronously or asynchronously,
diff --git a/lib/fs.js b/lib/fs.js
index b6cc49036..01a3c4d5e 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -55,6 +55,8 @@ var O_WRONLY = constants.O_WRONLY || 0;
var isWindows = process.platform === 'win32';
var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
+var errnoException = util._errnoException;
+
function rethrow() {
// Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
@@ -334,12 +336,6 @@ function stringToFlags(flag) {
return flag;
}
- // O_EXCL is mandated by POSIX, Windows supports it too.
- // Let's add a check anyway, just in case.
- if (!O_EXCL && ~flag.indexOf('x')) {
- throw errnoException('ENOSYS', 'fs.open(O_EXCL)');
- }
-
switch (flag) {
case 'r' : return O_RDONLY;
case 'rs' : return O_RDONLY | O_SYNC;
@@ -999,17 +995,6 @@ fs.appendFileSync = function(path, data, options) {
fs.writeFileSync(path, data, options);
};
-function errnoException(errorno, syscall) {
- // TODO make this more compatible with ErrnoException from src/node.cc
- // Once all of Node is using this function the ErrnoException from
- // src/node.cc should be removed.
- var e = new Error(syscall + ' ' + errorno);
- e.errno = e.code = errorno;
- e.syscall = syscall;
- return e;
-}
-
-
function FSWatcher() {
EventEmitter.call(this);
diff --git a/lib/net.js b/lib/net.js
index d30c002d4..c970595b5 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -25,7 +25,9 @@ var timers = require('timers');
var util = require('util');
var assert = require('assert');
var cares = process.binding('cares_wrap');
+
var cluster;
+var errnoException = util._errnoException;
function noop() {}
@@ -940,19 +942,6 @@ function afterConnect(status, handle, req, readable, writable) {
}
-function errnoException(errorno, syscall) {
- // TODO make this more compatible with ErrnoException from src/node.cc
- // Once all of Node is using this function the ErrnoException from
- // src/node.cc should be removed.
- var e = new Error(syscall + ' ' + errorno);
- e.errno = e.code = errorno;
- e.syscall = syscall;
- return e;
-}
-
-
-
-
function Server(/* [ options, ] listener */) {
if (!(this instanceof Server)) return new Server(arguments[0], arguments[1]);
events.EventEmitter.call(this);
diff --git a/lib/tty.js b/lib/tty.js
index 98d498a17..5d60ec660 100644
--- a/lib/tty.js
+++ b/lib/tty.js
@@ -26,6 +26,9 @@ var TTY = process.binding('tty_wrap').TTY;
var isTTY = process.binding('tty_wrap').isTTY;
var util = require('util');
+var errnoException = util._errnoException;
+
+
exports.isatty = function(fd) {
return isTTY(fd);
};
@@ -123,12 +126,3 @@ WriteStream.prototype.clearScreenDown = function() {
WriteStream.prototype.getWindowSize = function() {
return [this.columns, this.rows];
};
-
-
-// TODO share with net_uv and others
-function errnoException(errorno, syscall) {
- var e = new Error(syscall + ' ' + errorno);
- e.errno = e.code = errorno;
- e.syscall = syscall;
- return e;
-}
diff --git a/lib/util.js b/lib/util.js
index 4f9d06943..f02aa8f6a 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -601,3 +601,15 @@ exports.pump = exports.deprecate(function(readStream, writeStream, callback) {
call(err);
});
}, 'util.pump(): Use readableStream.pipe() instead');
+
+
+var uv;
+exports._errnoException = function(err, syscall) {
+ if (typeof uv === 'undefined') uv = process.binding('uv');
+ var errname = uv.errname(err);
+ var e = new Error(syscall + ' ' + errname);
+ e.code = errname;
+ e.errno = errname;
+ e.syscall = syscall;
+ return e;
+};