bluebird 3.1.1警告:在处理程序中创建了一个promise,但未从中返回

时间:2016-02-28 15:34:00

标签: node.js coffeescript promise bluebird

我从http://passportjs.org/docs/configure获取以下代码,并且自更新为bluebird后:3.1.1我继续获取http://bluebirdjs.com/docs/warning-explanations.html#warning-a-promise-was-created-in-a-handler-but-none-were-returned-from-it

passport.deserializeUser(function(id, done) {
  return User.findByIdOrThrowPr(id, 'company').then(function(user) {
    return done(null, user);
  })['catch'](function(err) {
    return done(err, null);
  });
});

给出了这些警告

Warning: a promise was created in a handler but was not returned from it
  at setViewLocals (/home/khine/Sandboxes/node-blade-boiler-template/app/app.coffee:96:11)
  at Layer.handle [as handle_request] (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/layer.js:95:5)
  at trim_prefix (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:312:13)
  at /home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:280:7
  at Function.process_params (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:330:12)
  at next (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:271:10)
  at /home/khine/Sandboxes/node-blade-boiler-template/node_modules/i18next/lib/i18next.js:119:13
  at /home/khine/Sandboxes/node-blade-boiler-template/node_modules/i18next/node_modules/i18next-client/i18next.js:992:21
  at Object.i18n.functions.extend.load (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/i18next/lib/i18nextWrapper.js:326:17)
  at init (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/i18next/node_modules/i18next-client/i18next.js:988:19)
  at Object.setLng (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/i18next/node_modules/i18next-client/i18next.js:1200:16)
  at i18n.handle (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/i18next/lib/i18next.js:117:14)
  at Layer.handle [as handle_request] (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/layer.js:95:5)
  at trim_prefix (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:312:13)
  at /home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:280:7
  at Function.process_params (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:330:12)
  at next (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:271:10)
  at SessionStrategy.strategy.pass (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/passport/lib/middleware/authenticate.js:325:9)
  at /home/khine/Sandboxes/node-blade-boiler-template/node_modules/passport/lib/strategies/session.js:65:12
  at pass (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/passport/lib/authenticator.js:327:31)
  at deserialized (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/passport/lib/authenticator.js:339:7)
  at /home/khine/Sandboxes/node-blade-boiler-template/app/authentication/index.coffee:43:5
  at processImmediate [as _immediateCallback] (timers.js:383:17)
From previous event:
  at /home/khine/Sandboxes/node-blade-boiler-template/app/authentication/index.coffee:42:41
  at pass (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/passport/lib/authenticator.js:347:9)
  at Authenticator.deserializeUser (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/passport/lib/authenticator.js:352:5)
  at SessionStrategy.authenticate (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/passport/lib/strategies/session.js:53:28)
  at attempt (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/passport/lib/middleware/authenticate.js:348:16)
  at authenticate (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/passport/lib/middleware/authenticate.js:349:7)
  at Layer.handle [as handle_request] (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/layer.js:95:5)
  at trim_prefix (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:312:13)
  at /home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:280:7
  at Function.process_params (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:330:12)
  at next (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:271:10)
  at initialize (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/passport/lib/middleware/initialize.js:53:5)
  at Layer.handle [as handle_request] (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/layer.js:95:5)
  at trim_prefix (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:312:13)
  at /home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:280:7
  at Function.process_params (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:330:12)
  at next (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:271:10)
  at /home/khine/Sandboxes/node-blade-boiler-template/app/translation.coffee:43:5
  at Layer.handle [as handle_request] (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/layer.js:95:5)
  at trim_prefix (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:312:13)
  at /home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:280:7
  at Function.process_params (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:330:12)
  at next (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:271:10)
  at /home/khine/Sandboxes/node-blade-boiler-template/node_modules/connect-flash/lib/flash.js:21:5
  at Layer.handle [as handle_request] (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/layer.js:95:5)
  at trim_prefix (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:312:13)
  at /home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:280:7
  at Function.process_params (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:330:12)
  at next (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:271:10)
  at /home/khine/Sandboxes/node-blade-boiler-template/node_modules/express-device/lib/device.js:46:26
  at Layer.handle [as handle_request] (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/layer.js:95:5)
  at trim_prefix (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:312:13)
  at /home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:280:7
  at Function.process_params (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:330:12)
  at next (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:271:10)
  at csrf (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/csurf/index.js:100:5)
  at Layer.handle [as handle_request] (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/layer.js:95:5)
  at trim_prefix (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:312:13)
  at /home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:280:7
  at Function.process_params (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:330:12)
  at next (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/express/lib/router/index.js:271:10)
  at /home/khine/Sandboxes/node-blade-boiler-template/node_modules/express-session/index.js:432:7
  at Command.callback (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/connect-redis/lib/connect-redis.js:148:14)
  at RedisClient.return_reply (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/redis/index.js:664:25)
  at JavascriptReplyParser.reply_parser.send_reply (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/redis/index.js:332:14)
  at JavascriptReplyParser.run (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/redis/lib/parsers/javascript.js:132:18)
  at JavascriptReplyParser.execute (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/redis/lib/parsers/javascript.js:107:10)
  at Socket.<anonymous> (/home/khine/Sandboxes/node-blade-boiler-template/node_modules/redis/index.js:131:27)
  at emitOne (events.js:77:13)
  at Socket.emit (events.js:169:7)
  at readableAddChunk (_stream_readable.js:146:16)
  at Socket.Readable.push (_stream_readable.js:110:10)
  at TCP.onread (net.js:523:20)

应用程序/ app.coffee

setViewLocals = (req, res, next) ->

  cartUserId = null
  #shopForUserId = null
  if req.isAuthenticated()
    if req.user.isStaff()
      cartUserId = req.user.shopFor
      #shopForUserId = req.user.shopFor
    else
      cartUserId = req.user._id
  Promise.resolve()
    .then -> if cartUserId then M.Cart.setActive(cartUserId)
    .then ->
      Promise.props
        collections: M.Collection.findUsedCachedPr()
        logos: M.Logos.findAllPr()
        categories: M.Category.findUsedCachedPr()
        affiliations: M.Affiliation.findAllPr()
        cart: cartUserId and M.Cart.findByIdOrNewPr(cartUserId)
        articles: M.Article.getUsedCategoriesPr()
        shopForUser: cartUserId and M.User.findByIdOrNull(cartUserId, ["company"])
        userDiscounts: adminRules.getRules(req.user)
        maintenance: M.Maintenance.underMaintenance()
        #userNotifications: M.Notification.getNotifications(req.user)
    .then (result) ->
      req.cartUser = result.shopForUser or req.user
      req.tt = translation.translateDbString
      req.tCountryNames = countries.getCountryNames
      affiliations = _(result.affiliations).sortBy('position').value()
      res.redirectWithFlash = redirectWithFlash
      _.extend res.locals,
        discountAvailable: Object.keys(result.userDiscounts).length > 0
        angularApp: false
        messages: req.flash()
        _csrf: req.csrfToken()
        user: req.user
        tt: translation.translateDbString
        menuCollections: result.collections
        logos: result.logos
        menuCategories: result.categories
        affiliations: affiliations
        articles: result.articles
        menuCart: result.cart
        shopForUser: result.shopForUser
        userDiscounts: result.userDiscounts
        maintenance: result.maintenance
        __collectionId: req.query.collectionId or ''
        __categoryId: req.query.categoryId or ''
        __color: req.query.color or ''
        _: _
        tCountryNames: countries.getCountryNames
        tCountry: countries.getCountryName
        allowedUrls: req.allowedUrls = adminUser.getAllowedUrls req.user
        currentYear: moment().format('YYYY')
        settings: res.locals.settings or {} # WTF?
        curLang: req.i18n.lng()
      _.extend res.locals.settings, __settings, assetsSettings
      null
    .asCallback next

任何建议,非常感谢

0 个答案:

没有答案