Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-192

Exception handling for callback in Base.prototype._callHandler() prevents higher level exception handling

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.4
    • Affects Version/s: 1.3
    • Component/s: None
    • Environment:
      mongoose 3.6.20 using mongodb 1.3.19

      We've come across this issue several time in our unit tests: a failed assertion (or any other exception thrown) never reaches the Mocha/Node exception handlers, if it is caused/thrown within certain Mongoose callbacks.

      Here's an example of a Mocha test that never returns:

      mongoose = require('mongoose')
      Model = mongoose.model('Model', new mongoose.Schema())
      mongoose.connect('mongodb://localhost/database')

      it('hanging test', (done) ->
      Model.aggregate({}, () ->

      1. Simulating a failed assertion:
        throw new Error('Some failed assertion')
        done()
        )
        )

      The exception is handled by Base.prototype._callHandler() and is never re-thrown again, so Mocha/Node (and before that Mongoose's utils.tick()) are unable to catch it.

      This doesn't happen for all queries. If find() or create() are used above, the exception is first caught by Mongoose's utils.tick() and then re-thrown, so Mocha is able to handle them in the end.

      Any thoughts on this?

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            rene Rene Hamburger
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: