src, lib: deduplicate errnoException
This commit is contained in:
parent
d4c14c1fe5
commit
0161ec87af
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
25
lib/dns.js
25
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,
|
||||
|
19
lib/fs.js
19
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);
|
||||
|
||||
|
15
lib/net.js
15
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);
|
||||
|
12
lib/tty.js
12
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;
|
||||
}
|
||||
|
12
lib/util.js
12
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;
|
||||
};
|
||||
|
12
src/node.js
12
src/node.js
@ -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');
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user