Why doesn't errors to the stdout on linux have line numbers or stack traces?

23 views
Skip to first unread message

Robert Steckroth

unread,
Jul 21, 2015, 4:24:48 PM7/21/15
to nodejs
Some nodejs errors are not very informative. How can I get nodejs to print line numbers and stack trace for this error?

Exaple ouptut of nodejs error to satdout -> 
Cannot read property 'sp' of undefined


Joe H

unread,
Jul 22, 2015, 9:11:54 AM7/22/15
to nodejs
You should call console.log(err.stack) instead of console.log(err)

Gustavo Machado

unread,
Jul 22, 2015, 9:11:54 AM7/22/15
to nod...@googlegroups.com
Hopefully this will clarify:

> var er = new Error('foo');
undefined
> er.toString()
'Error: foo'
> er.message
'foo'
> er.stack
'Error: foo\n    at repl:1:10\n    at REPLServer.self.eval (repl.js:110:21)\n    at repl.js:249:20\n    at REPLServer.self.eval (repl.js:122:7)\n    at Interface.<anonymous> (repl.js:239:12)\n    at Interface.EventEmitter.emit (events.js:95:17)\n    at Interface._onLine (readline.js:202:10)\n    at Interface._line (readline.js:531:8)\n    at Interface._ttyWrite (readline.js:760:14)\n    at ReadStream.onkeypress (readline.js:99:10)'
> er.stack.split('\n').forEach(function (line) { console.log(line); });
Error: foo
    at repl:1:10
    at REPLServer.self.eval (repl.js:110:21)
    at repl.js:249:20
    at REPLServer.self.eval (repl.js:122:7)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)

Cheers,
Gus

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/e9a85f84-c35d-4420-a081-be0acaa84423%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages