var isIp = net.isIP;
-function errnoException(err, syscall) {
+function errnoException(err, syscall, hostname) {
// FIXME(bnoordhuis) Remove this backwards compatibility shite and pass
// the true error to the user. ENOTFOUND is not even a proper POSIX error!
if (err === uv.UV_EAI_MEMORY ||
err === uv.UV_EAI_NONAME) {
err = 'ENOTFOUND';
}
+ var ex = null;
if (typeof err === 'string') { // c-ares error code.
- var ex = new Error(syscall + ' ' + err);
+ ex = new Error(syscall + ' ' + err);
ex.code = err;
ex.errno = err;
ex.syscall = syscall;
- return ex;
+ } else {
+ ex = util._errnoException(err, syscall);
+ }
+ if (hostname) {
+ ex.hostname = hostname;
}
- return util._errnoException(err, syscall);
+ return ex;
}
function onlookup(err, addresses) {
if (err) {
- return this.callback(errnoException(err, 'getaddrinfo'));
+ return this.callback(errnoException(err, 'getaddrinfo', this.hostname));
}
if (this.family) {
this.callback(null, addresses[0], this.family);
var req = {
callback: callback,
family: family,
+ hostname: hostname,
oncomplete: onlookup
};
var err = cares.getaddrinfo(req, hostname, family);
- if (err) throw errnoException(err, 'getaddrinfo');
+ if (err) throw errnoException(err, 'getaddrinfo', hostname);
callback.immediately = true;
return req;
function onresolve(err, result) {
if (err)
- this.callback(errnoException(err, this.bindingName));
+ this.callback(errnoException(err, this.bindingName, this.hostname));
else
this.callback(null, result);
}
var req = {
bindingName: bindingName,
callback: callback,
+ hostname: name,
oncomplete: onresolve
};
var err = binding(req, name);
});
+TEST(function test_reverse_failure(done) {
+ var req = dns.reverse('0.0.0.0', function(err) {
+ assert(err instanceof Error);
+ assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
+ assert.strictEqual(err.hostname, '0.0.0.0');
+
+ done();
+ });
+
+ checkWrap(req);
+});
+
+
+TEST(function test_lookup_failure(done) {
+ var req = dns.lookup('nosuchhostimsure', function(err) {
+ assert(err instanceof Error);
+ assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
+ assert.strictEqual(err.hostname, 'nosuchhostimsure');
+
+ done();
+ });
+
+ checkWrap(req);
+});
+
+
+TEST(function test_resolve_failure(done) {
+ var req = dns.resolve4('nosuchhostimsure', function(err) {
+ assert(err instanceof Error);
+ assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
+ assert.strictEqual(err.hostname, 'nosuchhostimsure');
+
+ done();
+ });
+
+ checkWrap(req);
+});
+
+
/* Disabled because it appears to be not working on linux. */
/* TEST(function test_lookup_localhost_ipv6(done) {
var req = dns.lookup('localhost', 6, function(err, ip, family) {