fix(shell): guard against empty or non-text clipboard on Ctrl+V paste#1812
Open
kevinWangSheng wants to merge 1 commit intoMoonshotAI:mainfrom
Open
fix(shell): guard against empty or non-text clipboard on Ctrl+V paste#1812kevinWangSheng wants to merge 1 commit intoMoonshotAI:mainfrom
kevinWangSheng wants to merge 1 commit intoMoonshotAI:mainfrom
Conversation
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
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.
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()returningNone, which prompt_toolkit'sPyperclipClipboard.get_data()doesn't handle — it runs"\n" in texton theNonevalue, raising aTypeError.This patch wraps the
get_data()call in atry/except TypeErrorso the paste is silently skipped instead of crashing. An additional guard onclipboard_data.textbeing falsy prevents downstream issues even if future prompt_toolkit versions change how they surfaceNoneclipboard content.The fix also covers the scenario from #1757 where
_try_paste_media()detects an image, warns about unsupported model, returnsFalse, and the fallback text-paste path hits the same crash.Checklist
make gen-changelogto update the changelog.make gen-docsto update the user documentation.