util,net: move _detailedException into util
This allows _detailedException() to be used by both the 'net' and 'dgram' modules to provide more informative error messages. PR-URL: https://github.com/iojs/io.js/pull/250 Reviewed-By: Bert Belder <bertbelder@gmail.com>
This commit is contained in:
parent
8a0e7d6566
commit
3937e8566d
21
lib/net.js
21
lib/net.js
@ -38,6 +38,7 @@ var WriteWrap = process.binding('stream_wrap').WriteWrap;
|
||||
|
||||
var cluster;
|
||||
var errnoException = util._errnoException;
|
||||
var detailedException = util._detailedException;
|
||||
|
||||
function noop() {}
|
||||
|
||||
@ -68,26 +69,6 @@ function isPipeName(s) {
|
||||
return util.isString(s) && toNumber(s) === false;
|
||||
}
|
||||
|
||||
// format exceptions
|
||||
function detailedException(err, syscall, address, port, additional) {
|
||||
var details;
|
||||
if (port && port > 0) {
|
||||
details = address + ':' + port;
|
||||
} else {
|
||||
details = address;
|
||||
}
|
||||
|
||||
if (additional) {
|
||||
details += ' - Local (' + additional + ')';
|
||||
}
|
||||
var ex = errnoException(err, syscall, details);
|
||||
ex.address = address;
|
||||
if (port) {
|
||||
ex.port = port;
|
||||
}
|
||||
return ex;
|
||||
}
|
||||
|
||||
exports.createServer = function() {
|
||||
return new Server(arguments[0], arguments[1]);
|
||||
};
|
||||
|
20
lib/util.js
20
lib/util.js
@ -756,3 +756,23 @@ exports._errnoException = function(err, syscall, original) {
|
||||
e.syscall = syscall;
|
||||
return e;
|
||||
};
|
||||
|
||||
|
||||
exports._detailedException = function(err, syscall, address, port, additional) {
|
||||
var details;
|
||||
if (port && port > 0) {
|
||||
details = address + ':' + port;
|
||||
} else {
|
||||
details = address;
|
||||
}
|
||||
|
||||
if (additional) {
|
||||
details += ' - Local (' + additional + ')';
|
||||
}
|
||||
var ex = exports._errnoException(err, syscall, details);
|
||||
ex.address = address;
|
||||
if (port) {
|
||||
ex.port = port;
|
||||
}
|
||||
return ex;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user