From 3344c16ec748b745f36a84d70d6ff9ce390789fb Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Tue, 24 Oct 2023 23:20:38 +0200 Subject: [PATCH] Better error location --- src/API.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/API.ts b/src/API.ts index a0e9b7e..09cca89 100644 --- a/src/API.ts +++ b/src/API.ts @@ -143,18 +143,25 @@ export class UserAPI { }; _reportError = (error: any): void => { - - const extractLineNumber = (error: Error) => { + const extractLineAndColumn = (error: Error) => { const stackLines = error.stack?.split("\n"); - if (stackLines && stackLines.length > 1) { - const match = stackLines[1].match(/:(\d+):/); - if (match) return parseInt(match[1], 10); + if (stackLines) { + for (const line of stackLines) { + if (line.includes('')) { + const match = line.match(/:(\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 errorMessage = lineNumber ? `${error.message} (Line: ${lineNumber})` : error.message; + const { line, column } = extractLineAndColumn(error); + const errorMessage = line && column + ? `${error.message} (Line: ${line - 2}, Column: ${column})` + : error.message; + + clearTimeout(this.errorTimeoutID); clearTimeout(this.printTimeoutID); this.app.interface.error_line.innerHTML = errorMessage;