Open chrisblakley opened 2 years ago
This tidbit from ChatGPT was particularly insightful– might be a nice stopgap until lineNumber
is available in all browsers:
The lineNumber property of a JavaScript Error object, which is available inside the catch() block, is not a standard part of the ECMAScript specification. It is supported by some modern browsers, including Firefox, but not by others. This is why the lineNumber property is only available in Firefox and not in other browsers.
To get the line number of an error in JavaScript, you can use the error.stack property, which contains a stack trace of the error. The stack trace includes the line number where the error occurred. Here is an example:
try {
// Do something that might throw an error.
} catch (error) {
// Get the line number of the error from the stack trace.
let lineNumber = error.stack.split('\n')[1].split(':')[1];
// Output the error message and line number.
console.log(error.message + ' (line ' + lineNumber + ')');
}
This code gets the stack trace of the error and then extracts the line number from the second line of the stack trace. It then outputs the error message and line number. Note that this method is not supported by all browsers and may not work in all cases.
Currently only Firefox supports
error.lineNumber
inside ofcatch()
statements, so we can't use it in Nebula. Monitor it so that if/when it becomes standard in all browsers that we can use it in all of Nebula's catches.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/lineNumber