Skip to content

Commit 8cbba34

Browse files
committed
fix: optimize error logging for Chrome DevTools
1 parent f3b5d47 commit 8cbba34

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

src/logger/consoleErrorLogger.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@ export class ConsoleErrorLogger extends QuickAddLogger {
99
const error = this.getQuickAddError(errorMsg, ErrorLevel.Error, stack, originalError);
1010
this.addMessageToErrorLog(error);
1111

12-
if (originalError) {
13-
console.error(this.formatOutputString(error), originalError);
14-
} else {
15-
console.error(this.formatOutputString(error));
16-
}
12+
// Always pass the original error or create a new one to leverage Dev Tools' stack trace UI
13+
const errorToLog = originalError || new Error(errorMsg);
14+
15+
// Just log the message as the first argument and the error object as the second
16+
console.error(this.formatOutputString(error), errorToLog);
1717
}
1818

1919
public logWarning(warningMsg: string, stack?: string, originalError?: Error) {
2020
const warning = this.getQuickAddError(warningMsg, ErrorLevel.Warning, stack, originalError);
2121
this.addMessageToErrorLog(warning);
2222

23-
if (originalError) {
24-
console.warn(this.formatOutputString(warning), originalError);
25-
} else {
26-
console.warn(this.formatOutputString(warning));
27-
}
23+
// Always pass the original error or create a new one to leverage Dev Tools' stack trace UI
24+
const errorToLog = originalError || new Error(warningMsg);
25+
26+
console.warn(this.formatOutputString(warning), errorToLog);
2827
}
2928

3029
public logMessage(logMsg: string, stack?: string, originalError?: Error) {
3130
const log = this.getQuickAddError(logMsg, ErrorLevel.Log, stack, originalError);
3231
this.addMessageToErrorLog(log);
3332

33+
// For regular logs, we'll still show the error if available
3434
if (originalError) {
3535
console.log(this.formatOutputString(log), originalError);
3636
} else {

src/logger/quickAddLogger.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ export abstract class QuickAddLogger implements ILogger {
1010
abstract logWarning(msg: string, stack?: string, originalError?: Error): void;
1111

1212
protected formatOutputString(error: QuickAddError): string {
13-
let output = `QuickAdd: (${error.level}) ${error.message}`;
14-
if (error.stack) {
15-
output += `\nStack trace: ${error.stack}`;
16-
}
17-
return output;
13+
// Just return the basic message without stack trace, as we'll pass the error object separately
14+
return `QuickAdd: (${error.level}) ${error.message}`;
1815
}
1916

2017
protected getQuickAddError(

0 commit comments

Comments
 (0)