From 20f1fefaffc600c13746343704cd1df27c3ef80c Mon Sep 17 00:00:00 2001 From: zero-plusplus Date: Sun, 3 Jul 2022 13:18:05 +0900 Subject: [PATCH] Fix: #229 Raw error message on Critical Error --- CHANGELOG.md | 1 + README.md | 1 + src/ahkDebug.ts | 43 ++++++++++++++++++++++++------------------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dffa9fb..e3cd78d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ Also want to check the development status, check the [commit history](https://gi * [#212](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/212) Some errors were not detected and raw error messages were output. This caused `useAutoJumpToError` to not work in some cases * [#215](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/215) The list of running AutoHotkey processes displayed before attaching does not display correctly when it contains multibyte strings * [#220](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/220) Grouping of messages using Debug Directive is not working, such as `; @Debug-Output:start`, `; @Debug-Output:end` +* [#229](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/229) Raw error message on Critical Error ## [1.11.0] - 2022-02-11 ### Added diff --git a/README.md b/README.md index 4c719d98..84b17976 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ This extension is a debugger adapter for [VSCode](https://code.visualstudio.com/ * Fixed: [#212](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/212) Some errors were not detected and raw error messages were output. This caused `useAutoJumpToError` to not work in some cases * Fixed: [#215](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/215) The list of running AutoHotkey processes displayed before attaching does not display correctly when it contains multibyte strings * Fixed: [#220](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/220) Grouping of messages using Debug Directive is not working, such as `; @Debug-Output:start`, `; @Debug-Output:end` + * Fixed: [#229](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/229) Raw error message on Critical Error * `1.11.0` - 2022-02-11 * Added: [#201](https://github.com/zero-plusplus/vscode-autohotkey-debug/issues/201) Add `useLoadedScripts` to launch.json diff --git a/src/ahkDebug.ts b/src/ahkDebug.ts index b6f9a701..dbdaf2ac 100644 --- a/src/ahkDebug.ts +++ b/src/ahkDebug.ts @@ -233,7 +233,8 @@ export class AhkDebugSession extends LoggingDebugSession { this.sendOutputEvent(this.errorMessage, 'stderr'); }) .on('outputdebug', (message: string) => { - this.sendOutputDebug(message); + this.errorMessage = this.fixPathOfRuntimeError(message); + this.sendOutputDebug(this.errorMessage); }); this.sendAnnounce(`${this.ahkProcess.command}`); await this.createServer(args); @@ -775,9 +776,7 @@ export class AhkDebugSession extends LoggingDebugSession { } catch (error: unknown) { if (error instanceof dbgp.DbgpCriticalError) { - this.raisedCriticalError = true; - this.sendAnnounce(error.message, 'stderr'); - this.sendTerminateEvent(); + this.criticalError(error); return; } @@ -948,15 +947,15 @@ export class AhkDebugSession extends LoggingDebugSession { if (-1 < errorMessage.search(/--->\t\d+:/gmu)) { const line = parseInt(errorMessage.match(/--->\t(?\d+):/u)!.groups!.line, 10); let fixed = errorMessage; - if (-1 < errorMessage.search(/^Error:\s{2}/gmu)) { - fixed = errorMessage.replace(/^(Error:\s{2})/gmu, `${this.config.program}:${line} : ==> `); + if (-1 < errorMessage.search(/^(Critical\s)?Error:\s{2}/gmu)) { + fixed = errorMessage.replace(/^((Critical\s)?Error:\s{2})/gmu, `${this.config.program}:${line} : ==> `); } else if (-1 < errorMessage.search(/^Error in #include file /u)) { fixed = errorMessage.replace(/Error in #include file "(.+)":\n\s*(.+)/gmu, `$1:${line} : ==> $2`); } fixed = fixed.replace(/\n(Specifically:)/u, ' $1'); - fixed = fixed.substr(0, fixed.indexOf('Line#')); + fixed = fixed.substring(0, fixed.indexOf('Line#')); return `${fixed.replace(/\s+$/u, '')}\n`; } return errorMessage.replace(/^(.+)\s\((\d+)\)\s:/gmu, `$1:$2 :`); @@ -1344,11 +1343,19 @@ export class AhkDebugSession extends LoggingDebugSession { metaVariables.set(`callstack${index}.${key}`, value); }); }); + metaVariables.set('callstack.trace', Object.entries(callstack).map(([ i, item ]) => { + const trace = `> ${item.path}:${item.line} [${item.name}]`; + if (i === '[1]') { + return `[Call Stack]\r\n${trace}`; + } + return trace; + }).join('\r\n')); const callstackNames = Object.fromEntries(Object.entries(callstack).map(([ index, callstackItem ]) => [ index, callstackItem.name ])); metaVariables.set('callstackNames', callstackNames); Object.entries(callstackNames).forEach(([ index, callstackName ]) => { metaVariables.set(`callstackNames${index}`, callstackName); }); + return metaVariables; } private async evaluateCondition(breakpoint: Breakpoint): Promise { @@ -1408,9 +1415,7 @@ export class AhkDebugSession extends LoggingDebugSession { } catch (error: unknown) { if (error instanceof dbgp.DbgpCriticalError) { - this.raisedCriticalError = true; - this.sendAnnounce(error.message, 'stderr'); - this.sendTerminateEvent(); + this.criticalError(error); } } @@ -1457,12 +1462,16 @@ export class AhkDebugSession extends LoggingDebugSession { } catch (error: unknown) { if (error instanceof dbgp.DbgpCriticalError) { - this.raisedCriticalError = true; - this.sendAnnounce(error.message, 'stderr'); - this.sendTerminateEvent(); + this.criticalError(error); } } } + private criticalError(error: Error): void { + this.raisedCriticalError = true; + const fixedMessage = this.fixPathOfRuntimeError(error.message); + this.sendAnnounce(fixedMessage, 'stderr'); + this.sendTerminateEvent(); + } private async evaluateLog(format: string, metaVariables = this.currentMetaVariableMap, logpoint?: Breakpoint): Promise { const unescapeLogMessage = (string: string): string => { return string.replace(/\\([{}])/gu, '$1'); @@ -1522,9 +1531,7 @@ export class AhkDebugSession extends LoggingDebugSession { const property = await timeoutPromise(this.session!.evaluate(variableName, undefined, logpoint ? maxDepth : 1), timeout_ms).catch((error: unknown) => { if (error instanceof dbgp.DbgpCriticalError) { - this.raisedCriticalError = true; - this.sendAnnounce(error.message, 'stderr'); - this.sendTerminateEvent(); + this.criticalError(error); return; } timeout(); @@ -1612,9 +1619,7 @@ export class AhkDebugSession extends LoggingDebugSession { } catch (error: unknown) { if (error instanceof dbgp.DbgpCriticalError) { - this.raisedCriticalError = true; - this.sendAnnounce(error.message, 'stderr'); - this.sendTerminateEvent(); + this.criticalError(error); } } }