0

I'm running a test but not able to determine the exact line where it fails I put this code:

try {
   my code    
} catch (e) {
   console.log('LineNumber', e.lineNumber);
   console.log('Stack', e.stack);    
}

Here is what I get:

LOG: 'LineNumber', undefined

LOG: 'Stack', 'TypeError: Cannot read property 'push' of null at MyClass.method (./MyClass.ts?:8:27925)

What is 8:27925? How to get the exact line number in a test with typescript?

fastcodejava
  • 39,895
  • 28
  • 133
  • 186

1 Answers1

1

LOG: 'LineNumber', undefined

The lineNumber property is non-standard and only available in Firefox. I suspect you're seeing the undefined value because you're not using Firefox. See Error.prototype.lineNumber for more info.

What is 8:27925?

This is part of the stack trace. I believe it is lineNumber:columnNumber.

The 8 is the line number where the Cannot read property 'push' of null at MyClass.method error was thrown.

The 27925 is the column number. I assume it is so large because the TypeScript source has been compiled and possibly minified.

Is the lineNumber:columnNumber convention documented anywhere? Please let me know in the comments if you know of something.

How to get the exact line number in a test with typescript?

See How can I determine the current line number in JavaScript?

Shannon Matthews
  • 9,649
  • 7
  • 44
  • 75