MoonshotAI / MoonshotAI/kimi-cli

Crash when clipboard is empty during Ctrl-V paste

Open Beginner friendly
#1,750 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
11.4k
Forks
1.3k
Avg merge
9h 47m
Merged PRs (30d)
2

Description

Bug Description

Unhandled exception occurs when pressing Ctrl-V with an empty clipboard.

Steps to Reproduce

  1. Clear clipboard (or have empty clipboard)
  2. Press Ctrl-V in kimi CLI input box

Environment

  • macOS
  • Kimi Code CLI version: (run /version to get)
  • Terminal: ghostty

Error Traceback

Exception argument of type 'NoneType' is not iterable
File "/opt/homebrew/Cellar/python@3.13/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/events.py", line 89, in _run
self._context.run(self._callback, *self._args)
File ".../prompt_toolkit/application/application.py", line 714, in read_from_input_in_context context.copy().run(read_from_input)
File ".../prompt_toolkit/clipboard/pyperclip.py", line 41, in _ type=SelectionType.LINES if "\n" in text else SelectionType.CHARACTERS, ^^^
^^^^^^^^^

Root Cause

In prompt_toolkit/clipboard/pyperclip.py line 41, the code checks "\n" in text without first verifying that text is not None. When
clipboard is empty, text is None, causing TypeError: argument of type 'NoneType' is not iterable.

Suggested Fix

Add a null check before the in operator:

type=SelectionType.LINES if text and "\n" in text else SelectionType.CHARACTERS,

---

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in prompt_toolkit/clipboard/pyperclip.py at the line shown in the traceback, then reproduce the crash with an empty clipboard while pressing Ctrl-V in the Kimi CLI input box. Verify that empty clipboard pastes no longer raise the reported NoneType exception, while normal clipboard content continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.