Skip to content

fix(shell): guard against empty or non-text clipboard on Ctrl+V paste#1812

Open
kevinWangSheng wants to merge 1 commit intoMoonshotAI:mainfrom
kevinWangSheng:fix/clipboard-paste-crash
Open

fix(shell): guard against empty or non-text clipboard on Ctrl+V paste#1812
kevinWangSheng wants to merge 1 commit intoMoonshotAI:mainfrom
kevinWangSheng:fix/clipboard-paste-crash

Conversation

@kevinWangSheng
Copy link
Copy Markdown

@kevinWangSheng kevinWangSheng commented Apr 9, 2026

Related Issue

Resolve #1750
Resolve #1757

Description

Pressing Ctrl+V crashes the CLI when the system clipboard is empty or holds non-text data (e.g. a screenshot copied from macOS). The root cause is pyperclip.paste() returning None, which prompt_toolkit's PyperclipClipboard.get_data() doesn't handle — it runs "\n" in text on the None value, raising a TypeError.

This patch wraps the get_data() call in a try/except TypeError so the paste is silently skipped instead of crashing. An additional guard on clipboard_data.text being falsy prevents downstream issues even if future prompt_toolkit versions change how they surface None clipboard content.

The fix also covers the scenario from #1757 where _try_paste_media() detects an image, warns about unsupported model, returns False, and the fallback text-paste path hits the same crash.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open with Devin

pyperclip.paste() returns None when the system clipboard is empty or
holds non-text data (e.g. a screenshot). This causes a TypeError inside
prompt_toolkit's PyperclipClipboard.get_data() because it assumes text
is always a str. Wrap the call in a try-except and add a null check on
the text attribute so the paste is silently skipped instead of crashing.

Closes MoonshotAI#1750
Closes MoonshotAI#1757
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ctrl+V crashes with TypeError when clipboard contains non-text data (e.g. screenshot) Crash when clipboard is empty during Ctrl-V paste

1 participant