类型错误 seneca 索引如果不是响应期间的函数



我写了一个简单的动作,它使用 seneca-mongo 存储模块连接到 mongo db,执行列表查询并获取结果。我可以看到查询成功并且获取了正确的结果。当我尝试将这些结果发送回客户端时,响应调用错误并显示以下消息和堆栈跟踪。

ERROR       act     root$           OUT             cmd:getparams,role:diff 11      {cmd:getparams,role:diff,payload:{id:scalaScan}}    ENTRY    (dqk22) -       seneca: Action cmd:getparams,role:diff callback threw: k.indexOf is not a function.     act_callback    {message:k.indexOf is not a function,pattern:cmd:getparams,role:diff,instance:Seneca/0.7.2/d0twcki9cmxg/1485517      TypeError: k.indexOf is not a function
    at /scratch/DiffAnalyzer/node_modules/seneca/node_modules/seneca-web/web.js:851:13
    at Function.forEach (/scratch/DiffAnalyzer/node_modules/lodash/dist/lodash.js:3298:15)
    at Object.defaultmodify [as modify] (/scratch/DiffAnalyzer/node_modules/seneca/node_modules/seneca-web/web.js:850:7)
    at respond (/scratch/DiffAnalyzer/node_modules/seneca/node_modules/seneca-web/web.js:654:22)
    at Seneca.<anonymous> (/scratch/DiffAnalyzer/node_modules/seneca/node_modules/seneca-web/web.js:401:7)
    at act_done (/scratch/DiffAnalyzer/node_modules/seneca/seneca.js:1554:16)
    at /scratch/DiffAnalyzer/node_modules/gate-executor/gate-executor.js:127:20
    at Seneca.<anonymous> (/scratch/DiffAnalyzer/analyze.js:613:5)
    at act_done (/scratch/DiffAnalyzer/node_modules/seneca/seneca.js:1554:16)
    at /scratch/DiffAnalyzer/node_modules/gate-executor/gate-executor.js:127:20
    at /scratch/DiffAnalyzer/node_modules/seneca-mongo-store/mongo-store.js:329:21
    at /scratch/DiffAnalyzer/node_modules/mongodb/lib/mongodb/cursor.js:271:33
    at /scratch/DiffAnalyzer/node_modules/mongodb/lib/mongodb/cursor.js:778:35
    at Cursor.close (/scratch/DiffAnalyzer/node_modules/mongodb/lib/mongodb/cursor.js:1009:5)
    at Cursor.nextObject (/scratch/DiffAnalyzer/node_modules/mongodb/lib/mongodb/cursor.js:778:17)
    at Cursor.each (/scratch/DiffAnalyzer/node_modules/mongodb/lib/mongodb/cursor.js:264:12)

我写的动作是

seneca.add("role:diff,cmd:getparams", function(msg, respond) {
    seneca.ready(function() {
        var collection = seneca.make$("paramStore");
        var f = msg.payload;
        seneca.log.info("Filter", f);
        collection.list$(f, function(err, ob) {
            if (err) {
                seneca.log.error(err);
                respond(err);
            } else {
                seneca.log.info("Result", ob);
                respond(null, ob);
            }
        });
    });
});

同一段代码正在工作,现在我收到此错误。不知道发生了什么变化。任何帮助/建议将不胜感激。

我面临的问题是因为模块的js文件中的这段代码

if( _.isObject( result.out ) ) {
    _.each(result.out,function(v,k){
      if(~k.indexOf('$') && 'http$' !== k) {
        delete result.out[k]
      }
    })

_.each 函数旨在解析 JSON 对象,在我的例子中,输出实际上是一个 JSON 数组。将数组包装到一个对象中解决了它。

最新更新