Skip to content

Commit

Permalink
dns: include host name in error message if available
Browse files Browse the repository at this point in the history
This makes errors more readable and similar to FS errors, which also
include file name.

Reviewed-By: Fedor Indutny <[email protected]>
  • Loading branch information
mmalecki authored and indutny committed Sep 16, 2014
1 parent 11d57a5 commit 174f7d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions test/internet/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -601,6 +605,7 @@ TEST(function test_resolve_failure(done) {
}

assert.strictEqual(err.hostname, 'nosuchhostimsure');
assert.ok(/nosuchhostimsure/.test(err.message));

done();
});
Expand Down

0 comments on commit 174f7d2

Please sign in to comment.