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
2 changes: 1 addition & 1 deletion src/McpResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export class McpResponse implements Response {
const devTools = context.getDevToolsUniverse();
return await ConsoleFormatter.from(consoleMessage, {
id: consoleMessageStableId,
fetchDetailedData: true,
fetchDetailedData: false,
devTools: devTools ?? undefined,
});
}
Expand Down
20 changes: 15 additions & 5 deletions src/formatters/ConsoleFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,24 @@ export class ConsoleFormatter {
}

this.#resolvedArgs = await Promise.all(
this.#msg.args().map(arg => arg.jsonValue()),
this.#msg.args().map(async (arg, i) => {
try {
return await arg.jsonValue();
} catch {
return `<error: Argument ${i} is no longer available>`;
}
}),
);

if (devTools) {
this.#resolvedStackTrace = await createStackTraceForConsoleMessage(
devTools,
this.#msg,
);
try {
this.#resolvedStackTrace = await createStackTraceForConsoleMessage(
devTools,
this.#msg,
);
} catch {
// ignore
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions tests/formatters/ConsoleFormatter.test.js.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ Message: log> Processing file:
### Arguments
Arg #0: file.txt
`;

exports[`ConsoleFormatter > toStringDetailed > handles \"Execution context is not available\" error in args 1`] = `
ID: 6
Message: log> Processing file:
### Arguments
Arg #0: <error: Argument 0 is no longer available>
`;
21 changes: 21 additions & 0 deletions tests/formatters/ConsoleFormatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,27 @@ describe('ConsoleFormatter', () => {
).toStringDetailed();
t.assert.snapshot?.(result);
});

it('handles "Execution context is not available" error in args', async t => {
const message = createMockMessage({
type: () => 'log',
text: () => 'Processing file:',
args: () => [
{
jsonValue: async () => {
throw new Error('Execution context is not available');
},
},
],
});
const formatter = await ConsoleFormatter.from(message, {
id: 6,
fetchDetailedData: true,
});
const result = formatter.toStringDetailed();
t.assert.snapshot?.(result);
assert.ok(result.includes('<error: Argument 0 is no longer available>'));
});
});
describe('toJSON', () => {
it('formats a console.log message', async () => {
Expand Down