Skip to content

Commands with complex syntax show "The user denied this operation" without prompting user #6028

@daniel-lxs

Description

@daniel-lxs

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:

  1. Auto-approval may be disabled
  2. No approval dialog was shown to the user
  3. The actual error is a parsing/processing failure

Root Cause Analysis

After investigating the codebase, I found the issue occurs in the approval flow:

  1. src/core/tools/executeCommandTool.ts (line 57):

    • Calls askApproval("command", command)
    • If askApproval returns false, it simply returns without pushing any error details
  2. src/core/assistant-message/presentAssistantMessage.ts (lines 268-286):

    • The askApproval function internally calls cline.ask()
    • If cline.ask() throws an error (e.g., parsing error), it's caught in a try-catch block
    • The catch block returns false and shows the generic "The user denied this operation" message
    • The actual error details are lost
  3. src/core/prompts/responses.ts (line 8):

    • Contains the generic toolDenied message that gets displayed

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:

  1. 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
    }
  2. Add specific error handling in executeCommandTool.ts to catch and report parsing errors before calling askApproval

  3. Consider adding a new response type in responses.ts for parsing/validation errors that's distinct from user denial

Steps to Reproduce

  1. Disable auto-approval for commands
  2. Have the AI execute a command with complex escape sequences like:
    gh issue comment 123 --body "This has \"quotes\" and \nnewlines"
  3. 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

No one assigned

    Labels

    Issue - In ProgressSomeone is actively working on this. Should link to a PR soon.bugSomething isn't workingerror-handlingux

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions