Search code examples
mongoosebluebird

Simple example for "a promise was created in a handler but was not returned from it"


I looked at every post here but nothing matches.

Using latest source

"mongoose": "^4.8.1"
"bluebird": "^3.4.7"

Using Bluebird the mongoose way

mongoose.Promise = require('bluebird');

Error happens bevor the "respHelper.resp..." call Where Trader.Model is the mongoose model "TraderModel = mongoose.model('Trader', Trader);"

TraderModel.findOne({_id: req.account.traderid})
.then(function(trader) {
  respHelper.resp(200, res, {trader: trader});
  return null
})
.catch(function(error) {
  eLogger.error("Could not get Trader", ERRORS.ERR_DATABASEERROR, [], {accountid: req.account._id, traderid: req.params.traderid, exception: error});
  respHelper.respErr(500, res, ERRORS.ERR_DATABASEERROR);
  return null;
});

Full stack trace:

(node:11912) Warning: a promise was created in a handler but was not returned from it, see goo.gl/rRqMUw
    at new Promise (d:\Projects\work\UCConnectAPI\server\node_modules\bluebird\js\release\promise.js:77:14)
    at Model.compile.model.Query.exec (d:\Projects\work\UCConnectAPI\server\node_modules\mongoose\lib\query.js:2536:17)
    at Model.compile.model.Query.Query.then (d:\Projects\work\UCConnectAPI\server\node_modules\mongoose\lib\query.js:2584:15)
    at module.exports.getTraderByAccount (d:\Projects\work\UCConnectAPI\server\app\controllers\controller_api_trader.js:25:4)
    at Layer.handle [as handle_request] (d:\Projects\work\UCConnectAPI\server\node_modules\express\lib\router\layer.js:95:5)
    at next (d:\Projects\work\UCConnectAPI\server\node_modules\express\lib\router\route.js:131:13)
    at Route.dispatch (d:\Projects\work\UCConnectAPI\server\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (d:\Projects\work\UCConnectAPI\server\node_modules\express\lib\router\layer.js:95:5)
    at d:\Projects\work\UCConnectAPI\server\node_modules\express\lib\router\index.js:277:22
    at Function.process_params (d:\Projects\work\UCConnectAPI\server\node_modules\express\lib\router\index.js:330:12)
    at next (d:\Projects\work\UCConnectAPI\server\node_modules\express\lib\router\index.js:271:10)
    at d:\Projects\work\UCConnectAPI\server\app\lib\apitokenmanager.js:59:9
    at runCallback (timers.js:649:20)
    at tryOnImmediate (timers.js:622:5)
    at processImmediate [as _immediateCallback] (timers.js:594:5)
From previous event:
    at d:\Projects\work\UCConnectAPI\server\app\lib\apitokenmanager.js:53:43
    at d:\Projects\work\UCConnectAPI\server\node_modules\jsonwebtoken\verify.js:27:18
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

EDIT: Added TraderModel

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var Trader = new Schema({
  // Trader profile datas
  companyName: String,
  ustIdent: String,
  plz: String,
  city: String,
  country: String,
  street: String,
  streetNumber: String,
  contactPersonTechnical: String,
  contactPersonBilling: String,
  email: String,
  // Accounts für den Trader
  accounts: [
    {
      accountid: {type: Schema.Types.ObjectId, ref: 'Account'},
    // Rechte
      rights: {
        allowAddAccount: Boolean
      }
    }
  ],
  // Kunden des Traders
  customerids: [{type: Schema.Types.ObjectId, ref: 'Customer', index: true}],
  // Sub-Trader (untergeordnet)
  traderids: [{type: Schema.Types.ObjectId, ref: 'Trader', index: true}],
  // Haupttrader (übergeordnet)
  traderid: {type: String, trim: true, index: {unique: true}},
  created: {type: Date, default: Date.now()}, // im system angelegt am....
  changed: {type: Date, default: Date.now(), index: true} // geändet am...
});
Trader.set('toJSON', {getters: true, virtuals: false, depopulate: true});

Trader.methods.filterForPublic = function() {
  var tmpJson = this.toJSON();
  var publicData = {
    id: tmpJson._id,
    traderid: tmpJson.traderid,
    companyName: tmpJson.companyName,
    ustIdent: tmpJson.ustIdent,
    plz: tmpJson.plz,
    city: tmpJson.city,
    street: tmpJson.street,
    streetNumber: tmpJson.streetNumber,
    country: tmpJson.country,
    contactPersonTechnical: tmpJson.contactPersonTechnical,
    contactPersonBilling: tmpJson.contactPersonBilling
  };
  return publicData;
};

var TraderModel = mongoose.model('Trader', Trader);

Solution

  • Sorry to blind to see :/

    Cause was on a a total different place. Shoudl have looked better at the stack trace.

    From previous event: at d:\Projects\work\UCConnectAPI\server\app\lib\apitokenmanager.js:53:43 at d:\Projects\work\UCConnectAPI\server\node_modules\jsonwebtoken\verify.js:27:18