diff options
author | Maciej MaĆecki <me@mmalecki.com> | 2014-08-06 16:53:59 +0200 |
---|---|---|
committer | Fedor Indutny <fedor@indutny.com> | 2014-09-16 15:32:04 +0400 |
commit | 174f7d2820dcb12f1b4b511840416a03cd65b9cf (patch) | |
tree | eab445a6bfbc9eadc804b7b70ccc17903735bf3e | |
parent | 11d57a535c21a64885808afd41612406ff854c69 (diff) | |
download | nodejs-174f7d2820dcb12f1b4b511840416a03cd65b9cf.tar.gz nodejs-174f7d2820dcb12f1b4b511840416a03cd65b9cf.tar.bz2 nodejs-174f7d2820dcb12f1b4b511840416a03cd65b9cf.zip |
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>
-rw-r--r-- | lib/dns.js | 2 | ||||
-rw-r--r-- | test/internet/test-dns.js | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/lib/dns.js b/lib/dns.js index c61e6e9fc..4eb34d665 100644 --- a/lib/dns.js +++ b/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; diff --git a/test/internet/test-dns.js b/test/internet/test-dns.js index 35a2e6b9b..60227df7c 100644 --- a/test/internet/test-dns.js +++ b/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(); }); |