dns: use template literals
authorBenjamin Gruenbaum <inglor@gmail.com>
Sun, 20 Mar 2016 13:13:51 +0000 (15:13 +0200)
committerMyles Borins <mborins@us.ibm.com>
Wed, 30 Mar 2016 20:12:16 +0000 (13:12 -0700)
Prefer the use of template string literals over string concatenation
in the dns module, makes dns consistent with other modules basically
doing https://github.com/nodejs/node/pull/5778 for it.

PR-URL: https://github.com/nodejs/node/pull/5809
Reviewed-By: James M Snell <jasnell@gmail.com>
lib/dns.js

index 6683eac..5a87b8c 100644 (file)
@@ -23,7 +23,8 @@ function errnoException(err, syscall, hostname) {
   }
   var ex = null;
   if (typeof err === 'string') {  // c-ares error code.
-    ex = new Error(syscall + ' ' + err + (hostname ? ' ' + hostname : ''));
+    const errHost = hostname ? ' ' + hostname : '';
+    ex = new Error(`${syscall} ${err}${errHost}`);
     ex.code = err;
     ex.errno = err;
     ex.syscall = syscall;
@@ -268,7 +269,7 @@ exports.resolve = function(hostname, type_, callback_) {
   if (typeof resolver === 'function') {
     return resolver(hostname, callback);
   } else {
-    throw new Error('Unknown type "' + type_ + '"');
+    throw new Error(`Unknown type "${type_}"`);
   }
 };
 
@@ -306,7 +307,7 @@ exports.setServers = function(servers) {
     if (ver)
       return newSet.push([ver, s]);
 
-    throw new Error('IP address is not properly formatted: ' + serv);
+    throw new Error(`IP address is not properly formatted: ${serv}`);
   });
 
   var r = cares.setServers(newSet);
@@ -316,8 +317,7 @@ exports.setServers = function(servers) {
     cares.setServers(orig.join(','));
 
     var err = cares.strerror(r);
-    throw new Error('c-ares failed to set servers: "' + err +
-                    '" [' + servers + ']');
+    throw new Error(`c-ares failed to set servers: "${err}" [${servers}]`);
   }
 };