【问题标题】:Node catch() error doesn't show file the error occured节点 catch() 错误不显示文件错误发生
【发布时间】:2017-07-16 07:01:50
【问题描述】:

我在节点中使用new --inspect 参数来调试我的应用程序Chrome Developer Tools。我的承诺链末尾有一个非常基本的catch,但返回的错误并没有清楚地显示它们来自哪里。

我能看到错误源自哪个文件吗?

  leagues(app).getLeagues(passData)
    .then(teamsApi.getNorsemenTeams)
      .then(filterBarGamesIndex)
    .then(gamesApi.getNorseGames)
    .then(gamesApi.getFilteredTeams)
    .then(function (passData) {
      res.render('games', {
        title: 'Results',
        passData: passData,
        type: req.originalUrl.split('/')[2]
      })
    })
      .catch(function(err) {
          console.error(err); //Line 35
      });
}

直接从控制台错误是:

TypeError: Cannot read property 'Intermediate_Division_2' of undefined
    at /var/www/beta.norsemanfc.co.uk/app/controllers/filterBar/fixturesIndex.js:27:62
    at Array.filter (native)
    at module.exports (/var/www/beta.norsemanfc.co.uk/app/controllers/filterBar/fixturesIndex.js:25:42)
    at process._tickCallback (internal/process/next_tick.js:103:7)

【问题讨论】:

  • 根据错误,您的错误似乎发生在filterBarGamesIndex
  • 我同意,但我的系统中不存在这样的文件:/
  • 你用的是什么浏览器?如果您使用的是 Firefox,您可以尝试 console.log(err.lineNumber),如 Mozilla page 所述。
  • @brennanenanen 这是 Node.js。
  • @PatrickRoberts 你是对的,奇怪的是我在搜索fixturesIndex,我在phpstorm 中使我的缓存无效,然后它找到了文件。

标签: javascript node.js error-handling node-inspector node-debugger


【解决方案1】:

您可能想要转储有关异常的更多信息,如

console.log(err.stack);

【讨论】:

  • 这导致了非常相似的错误,可悲的是TypeError: Cannot read property 'Intermediate_Division_2' of undefined at /var/www/beta.norsemanfc.co.uk/app/controllers/filterBar/fixturesIndex.js:27:62 at Array.filter (native) at module.exports (/var/www/beta.norsemanfc.co.uk/app/controllers/filterBar/fixturesIndex.js:25:42) at process._tickCallback (internal/process/next_tick.js:103:7)
  • 因为filterBar/fix‌​turesIndex.js 根本不是真正的文件。我相信这可能与我使用 jade 作为模板有关?
  • 这不是“非常相似”。那里有更多地点。
  • 不,它实际上是相同的,我的错误是只在 devtools 中显示错误。请查看更新的问题
猜你喜欢
  • 1970-01-01
  • 2018-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-21
  • 1970-01-01
  • 2018-10-31
相关资源
最近更新 更多