From 174f7d2820dcb12f1b4b511840416a03cd65b9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Ma=C5=82ecki?= Date: Wed, 6 Aug 2014 16:53:59 +0200 Subject: [PATCH] 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 --- lib/dns.js | 2 +- test/internet/test-dns.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/dns.js b/lib/dns.js index c61e6e9fc4..4eb34d6651 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 35a2e6b9bf..60227df7ca 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(); });