1

I am using the new --inspect parameter in node to debug my application with Chrome Developer Tools. I have a very basic catch at the end of my promise chain but the errors returned are not showing clearly where they came from.

Am I able to see which file the error originated in?

  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
      });
}

enter image description here

And directly from the console the error is:

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)
Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291
  • 1
    Based on the error, it appears your error occurred in `filterBarGamesIndex` – Patrick Roberts Jul 15 '17 at 22:47
  • I agree, but no such file exists in my system :/ – Jamie Hutber Jul 15 '17 at 22:49
  • What browser are you using? If you are using Firefox you could try `console.log(err.lineNumber)` as said on the [Mozilla page](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Error). – brennanenanen Jul 15 '17 at 22:49
  • @brennanenanen This is Node.js. – Patrick Roberts Jul 15 '17 at 22:50
  • @PatrickRoberts you are correct, weird that I was searching for `fixturesIndex`, i invalidated my cache in `phpstorm` and then it found the file. – Jamie Hutber Jul 15 '17 at 22:51
  • It seems that the `bug` if you can call it that is with using the `--inspect` it does not display the errors correctly – Jamie Hutber Jul 15 '17 at 22:54
  • @brennanenanen some tips are [`res.render()`](http://expressjs.com/en/4x/api.html#res.render), [`module.exports`](https://nodejs.org/api/modules.html#modules_module_exports), and `process._tickCallback` (in the stacktrace), which is visible in basically every Node.js error I've ever seen. – Patrick Roberts Jul 15 '17 at 22:55

1 Answers1

3

You might want to dump more information about the exception as in

console.log( err.stack );

Jarek Kulikowski
  • 1,399
  • 8
  • 9
  • 1
    That results in very similar error sadly `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)` – Jamie Hutber Jul 15 '17 at 22:43
  • As `filterBar/fix‌​turesIndex.js` isn't a real file at all. I believe this might be something to do with my using `jade` as my templates? – Jamie Hutber Jul 15 '17 at 22:44
  • That's not "very similar". You've got more locations there. – Patrick Roberts Jul 15 '17 at 22:44
  • No its actually identical, my mistake for only showing the error in the devtools. Please see updated questions – Jamie Hutber Jul 15 '17 at 22:46