prompt-toolkit / prompt-toolkit/python-prompt-toolkit

AssertionError cursor_position is None

Open
#1,119 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

I use xonsh as my shell with prompt-toolkit 3.0.4. Occasionally, I'll be typing in the prompt and get this traceback:

Unhandled exception in event loop:
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/eventloop/utils.py", line 72, in schedule
    func()
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 456, in redraw
    self._redraw()
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 523, in _redraw
    self.context.run(run_in_context)
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 509, in run_in_context
    self.renderer.render(self, self.layout)
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/renderer.py", line 568, in render
    layout.container.preferred_height(size.columns, size.rows).preferred,
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 324, in preferred_height
    dimensions = [
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 325, in <listcomp>
    c.preferred_height(width, max_available_height) for c in self._all_children
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 792, in preferred_height
    return self.content.preferred_height(width, max_available_height)
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 324, in preferred_height
    dimensions = [
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 325, in <listcomp>
    c.preferred_height(width, max_available_height) for c in self._all_children
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 2595, in preferred_height
    return self.content.preferred_height(width, max_available_height)
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 1620, in preferred_height
    return self._merge_dimensions(
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 1648, in _merge_dimensions
    preferred = get_preferred()
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 1613, in preferred_content_height
    return self.content.preferred_height(
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/layout/controls.py", line 639, in preferred_height
    content = self.create_content(width, height=1)  # Pass a dummy '1' as height.
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/layout/controls.py", line 761, in create_content
    document = buffer.document
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/buffer.py", line 524, in document
    return self._document_cache[
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/cache.py", line 98, in __missing__
    result = self.get_value(*key)
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/prompt_toolkit/document.py", line 98, in __init__
    assert cursor_position is None or cursor_position <= len(text), AssertionError(

Exception cursor_position=9, len_text=4
Press ENTER to continue...                                                                                                                                                
~ $ cd ~/p/che

Sometimes, I hit enter and the error repeats. Other times, I hit Enter and can continue.

I've just updated to prompt_toolkit==3.0.5. I'll report back here if the issue repeats.

Contributor guide

No contributing guide indexed for this repository

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 with the traceback path through prompt_toolkit/buffer.py, cache.py, document.py, and layout/controls.py, focusing on how cursor_position=9 and len_text=4 arise during redraw. Reproduce the intermittent prompt failure with the reported xonsh and prompt-toolkit versions, then add a regression test and verify that repeated redraws no longer raise the assertion.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.