dns: fix ReferenceError in resolve() error path
authorXidorn Quan <quanxunzhen@gmail.com>
Sun, 3 Mar 2013 04:53:51 +0000 (12:53 +0800)
committerBen Noordhuis <info@bnoordhuis.nl>
Mon, 4 Mar 2013 15:20:40 +0000 (16:20 +0100)
A typo in the variable name makes it throw a ReferenceError instead of
the expected "Unknown type" error when dns.resolve() is passed a bad
record type argument.

Fixes the following exception:

  ReferenceError: type is not defined
    at Object.exports.resolve (dns.js:189:40)
    at /Users/bnoordhuis/src/master/test/simple/test-c-ares.js:48:9
    <snip>

lib/dns.js
test/simple/test-c-ares.js

index 86b01ce..ad919cc 100644 (file)
@@ -186,7 +186,7 @@ exports.resolve = function(domain, type_, callback_) {
   if (typeof resolver === 'function') {
     return resolver(domain, callback);
   } else {
-    throw new Error('Unknown type "' + type + '"');
+    throw new Error('Unknown type "' + type_ + '"');
   }
 };
 
index 7210dc2..3a3a922 100644 (file)
@@ -42,6 +42,11 @@ dns.lookup('::1', function(error, result, addressType) {
   assert.equal(6, addressType);
 });
 
+// Try calling resolve with an unsupported type.
+assert.throws(function() {
+  dns.resolve('www.google.com', 'HI');
+}, /Unknown type/);
+
 // Windows doesn't usually have an entry for localhost 127.0.0.1 in
 // C:\Windows\System32\drivers\etc\hosts
 // so we disable this test on Windows.