Browse Source

dns: include host name in error message if available

This makes errors more readable and similar to FS errors, which also
include file name.

Reviewed-By: Fedor Indutny <fedor@indutny.com>
v0.11.14-release
Maciej Małecki 11 years ago
committed by Fedor Indutny
parent
commit
174f7d2820
  1. 2
      lib/dns.js
  2. 5
      test/internet/test-dns.js

2
lib/dns.js

@ -38,7 +38,7 @@ function errnoException(err, syscall, hostname) {
}
var ex = null;
if (typeof err === 'string') { // c-ares error code.
ex = new Error(syscall + ' ' + err);
ex = new Error(syscall + ' ' + err + (hostname ? ' ' + hostname : ''));
ex.code = err;
ex.errno = err;
ex.syscall = syscall;

5
test/internet/test-dns.js

@ -431,6 +431,7 @@ TEST(function test_lookup_failure(done) {
assert.strictEqual(err.errno, dns.NOTFOUND);
assert.strictEqual(err.errno, 'ENOTFOUND');
assert.ok(!/ENOENT/.test(err.message));
assert.ok(/does\.not\.exist/.test(err.message));
done();
});
@ -553,6 +554,7 @@ TEST(function test_lookupservice_invalid(done) {
var req = dns.lookupService('1.2.3.4', 80, function(err, host, service) {
assert(err instanceof Error);
assert.strictEqual(err.code, 'ENOTFOUND');
assert.ok(/1\.2\.3\.4/.test(err.message));
done();
});
@ -566,6 +568,7 @@ TEST(function test_reverse_failure(done) {
assert(err instanceof Error);
assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
assert.strictEqual(err.hostname, '0.0.0.0');
assert.ok(/0\.0\.0\.0/.test(err.message));
done();
});
@ -579,6 +582,7 @@ TEST(function test_lookup_failure(done) {
assert(err instanceof Error);
assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
assert.strictEqual(err.hostname, 'nosuchhostimsure');
assert.ok(/nosuchhostimsure/.test(err.message));
done();
});
@ -601,6 +605,7 @@ TEST(function test_resolve_failure(done) {
}
assert.strictEqual(err.hostname, 'nosuchhostimsure');
assert.ok(/nosuchhostimsure/.test(err.message));
done();
});

Loading…
Cancel
Save