Copilot CLI: Handle errors during tool invocation formatting#4697
Queued
DonJayamanne wants to merge 1 commit intomainfrom
Queued
Copilot CLI: Handle errors during tool invocation formatting#4697DonJayamanne wants to merge 1 commit intomainfrom
DonJayamanne wants to merge 1 commit intomainfrom
Conversation
joshspicer
approved these changes
Mar 25, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves resilience of Copilot CLI chat tool-invocation rendering by catching exceptions thrown by tool invocation formatters so a single formatter bug doesn’t break the overall session UI.
Changes:
- Wrap tool completion “post formatter” execution in a try/catch and attempt a generic completion fallback on failure.
- Wrap tool invocation “pre formatter” execution in a try/catch and (optionally) log formatter failures.
- Extend
createCopilotCLIToolInvocation(...)to accept an optionalILoggerfor error reporting.
Comments suppressed due to low confidence (2)
src/extension/chatSessions/copilotcli/common/copilotCLITools.ts:933
createCopilotCLIToolInvocationnow swallows formatter exceptions, but if the formatter throws before settinginvocationMessage/pastTenseMessage/toolSpecificData, the UI may show a blank or unhelpful tool invocation. Consider setting a genericUsing tool: .../Used tool: ...message (and optionally input args) before calling the formatter, and in the catch block ensure a minimal fallback display is filled in (not just logging).
try {
(formatter as Formatter)(invocation, toolCall, editId, workingDirectory);
} catch (err) {
logger?.error(err, `Failed to format tool invocation for tool: ${toolCall.toolName}`);
}
src/extension/chatSessions/copilotcli/common/copilotCLITools.ts:884
- The new optional
loggerparameter isn’t currently passed by any call sites in this module (e.g.processToolExecutionStartstill callscreateCopilotCLIToolInvocation(..., editId, workingDirectory)), so formatter errors will generally be swallowed without any log in production. Either plumb anILoggerdown from the caller (and/or make it required) or use an existing logger available in this codepath so failures are observable.
export function createCopilotCLIToolInvocation(data: {
toolCallId: string; toolName: string; arguments?: unknown; mcpServerName?: string | undefined;
mcpToolName?: string | undefined;
}, editId?: string, workingDirectory?: URI, logger?: ILogger): ChatToolInvocationPart | ChatResponseMarkdownPart | ChatResponseThinkingProgressPart | undefined {
Any commits made after this event will not be merged.
Any commits made after this event will not be merged.
Any commits made after this event will not be merged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.