Skip to content

Commit

Permalink
Fix: #229
Browse files Browse the repository at this point in the history
Raw error message on Critical Error
  • Loading branch information
zero-plusplus committed Jul 3, 2022
1 parent 97f5a1d commit 20f1fef
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 24 additions & 19 deletions src/ahkDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -948,15 +947,15 @@ export class AhkDebugSession extends LoggingDebugSession {
if (-1 < errorMessage.search(/--->\t\d+:/gmu)) {
const line = parseInt(errorMessage.match(/--->\t(?<line>\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 :`);
Expand Down Expand Up @@ -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<boolean> {
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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<MetaVariableValue[]> {
const unescapeLogMessage = (string: string): string => {
return string.replace(/\\([{}])/gu, '$1');
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 20f1fef

Please sign in to comment.