fix(Code Node): Error formatting fix (#16719)

This commit is contained in:
Michael Kret
2025-06-27 12:18:26 +03:00
committed by GitHub
parent 0775fd859e
commit 8f9ce72dc4
2 changed files with 78 additions and 7 deletions

View File

@@ -28,15 +28,16 @@ export class ExecutionError extends ApplicationError {
* Populate error `message` and `description` from error `stack`.
*/
private populateFromStack() {
const stackRows = this.stack.split('\n');
const stackRows = this.stack && typeof this.stack === 'string' ? this.stack.split('\n') : [];
if (stackRows.length === 0) {
this.message = 'Unknown error';
return;
}
const messageRow = stackRows.find((line) => line.includes('Error:'));
const lineNumberRow = stackRows.find((line) => line.includes('Code:'));
const lineNumberDisplay = this.toLineNumberDisplay(lineNumberRow);
const lineNumberDisplay = this.toLineNumberDisplay(lineNumberRow) || '';
if (!messageRow) {
this.message = `Unknown error ${lineNumberDisplay}`;
@@ -52,7 +53,7 @@ export class ExecutionError extends ApplicationError {
return;
}
this.message = `${errorDetails} ${lineNumberDisplay}`;
this.message = `${errorDetails} ${lineNumberDisplay}`.trim();
}
private toLineNumberDisplay(lineNumberRow?: string) {
@@ -74,10 +75,16 @@ export class ExecutionError extends ApplicationError {
private toErrorDetailsAndType(messageRow?: string) {
if (!messageRow) return [null, null];
const [errorDetails, errorType] = messageRow
.split(':')
.reverse()
.map((i) => i.trim());
// Remove "Error: " prefix added by stacktrace formatting
messageRow = messageRow.replace(/^Error: /, '');
const colonIndex = messageRow.indexOf(': ');
if (colonIndex === -1) {
return [messageRow.trim(), null];
}
const errorType = messageRow.substring(0, colonIndex).trim();
const errorDetails = messageRow.substring(colonIndex + 2).trim();
return [errorDetails, errorType === 'Error' ? null : errorType];
}