help icon indicating copy to clipboard operation
help copied to clipboard

error lineNumber and filename

Open saurav2501 opened this issue 9 years ago • 6 comments

  • Node.js Version: 6.10.2
  • OS: windows 10

I'm not able to track error lineNumber and fileName using error.lineName or error.fileName ??

saurav2501 avatar Jul 27 '17 14:07 saurav2501

Can you give more context? An example of what you’re trying to do or what doesn’t work?

addaleax avatar Jul 27 '17 14:07 addaleax

I'm trying to log error lineNumber and fileName in a file using error.lineNumber and error.fileName but it is showing undefined for linenumber and filename. But it is showing result for error name and code using error.name and error.code. I want same for error lineNumber and fileName. Kindly help me through this.

On Thu, Jul 27, 2017 at 8:15 PM, Anna Henningsen [email protected] wrote:

Can you give more context? An example of what you’re trying to do or what doesn’t work?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nodejs/help/issues/756#issuecomment-318383951, or mute the thread https://github.com/notifications/unsubscribe-auth/AISs-Vx9oimhk75mHKJpeucofGbfvAU7ks5sSKKDgaJpZM4OlYkz .

saurav2501 avatar Jul 27 '17 14:07 saurav2501

They're non-standard properties. More specifically, they are Mozilla extensions: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/lineNumber

bnoordhuis avatar Jul 27 '17 15:07 bnoordhuis

You can try to parse the error stack (err.stack) which usually contains file names and line numbers, but this is kind of hacky.

tniessen avatar Jul 27 '17 15:07 tniessen

https://github.com/v8/v8/wiki/Stack-Trace-API is a better alternative to parsing the stringified stack trace, fwiw. Maybe that helps.

addaleax avatar Jul 27 '17 15:07 addaleax

closing as answered, please let me know if that is not the case.

gireeshpunathil avatar Mar 10 '18 14:03 gireeshpunathil