"utils not defined" Error when throwing error on using strict: true with no callback

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • 2.0.6
    • Affects Version/s: 2.0.2, 2.0.5
    • Component/s: None
    • Environment:
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Hi!

      Using this code:

      index.js
      var MongoClient = require("mongodb").MongoClient;
      
      var mc = new MongoClient();
      mc.connect("mongodb://mongodb-01/boomerang",function(err,db) {
              var coll = db.collection("webcollections",{ strict: true });
      
      });
      

      I accomplished breaking the mongodb node driver, due to a typo in the collection.js sourcecode:

      bash
      Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      $> node index.js
      
      /home/andreas/tmp/mg/node_modules/mongodb/lib/mongo_client.js:386
                throw err
                      ^
      ReferenceError: utils is not defined
          at collection (/home/andreas/tmp/mg/node_modules/mongodb/lib/db.js:302:13)
          at /home/andreas/tmp/mg/index.js:5:16
          at /home/andreas/tmp/mg/node_modules/mongodb/lib/mongo_client.js:383:11
          at process._tickCallback (node.js:419:13)
      (21:05) andreas@[kemp] ~/tmp/mg $> cat index.js
      var MongoClient = require("mongodb").MongoClient;
      
      var mc = new MongoClient();
      mc.connect("mongodb://mongodb-01/boomerang",function(err,db) {
              var coll = db.collection("webcollections",{ strict: true });
      
      });
      $> cat node_modules/mongodb/package.json | jq .version
      "2.0.5"
      $>
      

      Same is also true in "2.0.2"

      The offending line is:

      collection.js
       if(typeof callback != 'function') {
            throw utils.toError(f("A callback is required in strict mode. While getting collection %s.", collectionName));
          }
      

      There is not variable utils as such defined in the code, however require() points to a utils.js. I haven't had the chance yet to look at the code or understand it or contribute to it but slowly considering it.

      Anyway thanks in advance!

            Assignee:
            Christian Amor Kvalheim
            Reporter:
            Andreas Marschke
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: