Better error location
This commit is contained in:
23
src/API.ts
23
src/API.ts
@ -143,18 +143,25 @@ export class UserAPI {
|
|||||||
};
|
};
|
||||||
|
|
||||||
_reportError = (error: any): void => {
|
_reportError = (error: any): void => {
|
||||||
|
const extractLineAndColumn = (error: Error) => {
|
||||||
const extractLineNumber = (error: Error) => {
|
|
||||||
const stackLines = error.stack?.split("\n");
|
const stackLines = error.stack?.split("\n");
|
||||||
if (stackLines && stackLines.length > 1) {
|
if (stackLines) {
|
||||||
const match = stackLines[1].match(/:(\d+):/);
|
for (const line of stackLines) {
|
||||||
if (match) return parseInt(match[1], 10);
|
if (line.includes('<anonymous>')) {
|
||||||
|
const match = line.match(/<anonymous>:(\d+):(\d+)/);
|
||||||
|
if (match) return { line: parseInt(match[1], 10), column: parseInt(match[2], 10) };
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return { line: null, column: null };
|
||||||
};
|
};
|
||||||
|
|
||||||
const lineNumber = extractLineNumber(error);
|
const { line, column } = extractLineAndColumn(error);
|
||||||
const errorMessage = lineNumber ? `${error.message} (Line: ${lineNumber})` : error.message;
|
const errorMessage = line && column
|
||||||
|
? `${error.message} (Line: ${line - 2}, Column: ${column})`
|
||||||
|
: error.message;
|
||||||
|
|
||||||
|
|
||||||
clearTimeout(this.errorTimeoutID);
|
clearTimeout(this.errorTimeoutID);
|
||||||
clearTimeout(this.printTimeoutID);
|
clearTimeout(this.printTimeoutID);
|
||||||
this.app.interface.error_line.innerHTML = errorMessage;
|
this.app.interface.error_line.innerHTML = errorMessage;
|
||||||
|
|||||||
Reference in New Issue
Block a user