Permalink
Browse files

src, lib: deduplicate errnoException

  • Loading branch information...
1 parent d4c14c1 commit 0161ec87af3d71b10d8ce679c8a1a64358fae8dc @bnoordhuis bnoordhuis committed Jul 16, 2013
Showing with 28 additions and 92 deletions.
  1. +1 −15 lib/child_process.js
  2. +1 −8 lib/dgram.js
  3. +5 −20 lib/dns.js
  4. +2 −17 lib/fs.js
  5. +2 −13 lib/net.js
  6. +3 −9 lib/tty.js
  7. +12 −0 lib/util.js
  8. +2 −10 src/node.js
View
@@ -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;
View
@@ -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;
-}
View
@@ -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,
View
@@ -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);
View
@@ -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);
View
@@ -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;
-}
View
@@ -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;
+};
View
@@ -459,16 +459,6 @@
if (process._print_eval) console.log(result);
}
- 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 createWritableStdioStream(fd) {
var stream;
var tty_wrap = process.binding('tty_wrap');
@@ -651,6 +641,7 @@
}
if (r) {
+ var errnoException = NativeModule.require('util')._errnoException;
throw errnoException(process._errno, 'kill');
}
@@ -685,6 +676,7 @@
var r = wrap.start(signum);
if (r) {
wrap.close();
+ var errnoException = NativeModule.require('util')._errnoException;
throw errnoException(process._errno, 'uv_signal_start');
}

0 comments on commit 0161ec8

Please sign in to comment.