Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/McpResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,6 @@ export class McpResponse implements Response {
);
}
detailedConsoleMessage = formatter;
} else {
detailedConsoleMessage = await ConsoleFormatter.from(message as Error, {
id: consoleMessageStableId,
});
}
}

Expand Down Expand Up @@ -351,9 +347,7 @@ export class McpResponse implements Response {
}
return formatter;
}
return await ConsoleFormatter.from(item as Error, {
id: consoleMessageStableId,
});
return null;
},
),
)
Expand Down
12 changes: 4 additions & 8 deletions src/formatters/ConsoleFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export interface ConsoleFormatterOptions {
}

export class ConsoleFormatter {
#msg: ConsoleMessage | Error | SymbolizedError;
#msg: ConsoleMessage | SymbolizedError;
#resolvedArgs: unknown[] = [];
#resolvedStackTrace?: DevTools.DevTools.StackTrace.StackTrace.StackTrace;
#id?: number;

private constructor(
msg: ConsoleMessage | Error | SymbolizedError,
msg: ConsoleMessage | SymbolizedError,
options?: ConsoleFormatterOptions,
) {
this.#msg = msg;
Expand All @@ -36,7 +36,7 @@ export class ConsoleFormatter {
}

static async from(
msg: ConsoleMessage | Error | UncaughtError,
msg: ConsoleMessage | UncaughtError,
options?: ConsoleFormatterOptions,
): Promise<ConsoleFormatter> {
if (msg instanceof UncaughtError) {
Expand All @@ -60,17 +60,13 @@ export class ConsoleFormatter {
}

#isConsoleMessage(
msg: ConsoleMessage | Error | SymbolizedError,
msg: ConsoleMessage | SymbolizedError,
): msg is ConsoleMessage {
// No `instanceof` as tests mock `ConsoleMessage`.
return 'args' in msg && typeof msg.args === 'function';
}

async #loadDetailedData(devTools?: TargetUniverse): Promise<void> {
if (this.#msg instanceof Error) {
return;
}

if (this.#isConsoleMessage(this.#msg)) {
this.#resolvedArgs = await Promise.all(
this.#msg.args().map(async (arg, i) => {
Expand Down