-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Bug Description
Certain commands, particularly those with complex escape sequences or special characters, fail with the error message "The user denied this operation" without ever showing an approval prompt to the user. This is misleading because the user never actually denied anything - the command failed during parsing/processing before the approval UI could be displayed.
Example
The following command triggers this issue:
gh issue comment 5427 --body "Hey, I've been investigating this issue and I think I found the root cause..."When the command contains escaped quotes, newlines, or other special characters, it fails with "The user denied this operation" even though:
- Auto-approval may be disabled
- No approval dialog was shown to the user
- The actual error is a parsing/processing failure
Root Cause Analysis
After investigating the codebase, I found the issue occurs in the approval flow:
-
src/core/tools/executeCommandTool.ts(line 57):- Calls
askApproval("command", command) - If
askApprovalreturnsfalse, it simply returns without pushing any error details
- Calls
-
src/core/assistant-message/presentAssistantMessage.ts(lines 268-286):- The
askApprovalfunction internally callscline.ask() - If
cline.ask()throws an error (e.g., parsing error), it's caught in a try-catch block - The catch block returns
falseand shows the generic "The user denied this operation" message - The actual error details are lost
- The
-
src/core/prompts/responses.ts(line 8):- Contains the generic
toolDeniedmessage that gets displayed
- Contains the generic
Impact
- Users see a misleading error message suggesting they denied something they were never asked about
- The actual error (parsing failure, invalid syntax, etc.) is hidden from the user
- This bypasses auto-approval settings entirely since the error occurs before any UI interaction
- Users cannot debug or fix the actual issue because they don't know what went wrong
Proposed Solution
Modify the error handling in presentAssistantMessage.ts to:
-
Preserve the actual error when
cline.ask()fails:try { const { response, text, images } = await cline.ask(...) // ... existing code } catch (error) { // Instead of silently returning false const errorMessage = error.message || 'Unknown error occurred while processing command' await cline.say("error", errorMessage) pushToolResult(formatResponse.toolError(errorMessage)) return false }
-
Add specific error handling in
executeCommandTool.tsto catch and report parsing errors before callingaskApproval -
Consider adding a new response type in
responses.tsfor parsing/validation errors that's distinct from user denial
Steps to Reproduce
- Disable auto-approval for commands
- Have the AI execute a command with complex escape sequences like:
gh issue comment 123 --body "This has \"quotes\" and \nnewlines" - Observe that "The user denied this operation" appears without any approval prompt
Expected Behavior
When a command fails to parse or process:
- Show the actual error message (e.g., "Failed to parse command: Invalid escape sequence at position X")
- Do NOT show "The user denied this operation" unless the user actually clicked a deny button
- Allow users to understand and fix the actual issue
Additional Context
This issue was discovered when trying to use gh issue comment commands with complex formatted text. The same issue likely affects other commands with special characters, escape sequences, or complex syntax.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status