Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch IndexError on empty Variables state #653

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

mvanderkamp
Copy link
Contributor

@mvanderkamp mvanderkamp commented Jun 3, 2024

To reproduce:

  1. bash try-the-debugger.sh
  2. Go to the variables pane while it is still empty
  3. Press m or any other command that would ordinarily modify how a variable is displayed.
Traceback
python version: 3.11.9 (main, Apr  2 2024, 08:25:04) [Clang 15.0.0 (clang-1500.3.9.4)]
pudb version: 2024.1
urwid version: 2...6...1.2
Traceback (most recent call last):
  File "/Users/mvanderkamp/projects/pudb/pudb/debugger.py", line 2843, in event_loop
    toplevel.keypress(self.size, k)
  File "/Users/mvanderkamp/projects/pudb/pudb/ui_tools.py", line 131, in keypress
    result = self._w.keypress(size, key)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mvanderkamp/projects/pudb/venv/lib/python3.11/site-packages/urwid/widget/frame.py", line 526, in keypress
    return self.body.keypress((maxcol, remaining), key)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mvanderkamp/projects/pudb/venv/lib/python3.11/site-packages/urwid/widget/widget.py", line 729, in keypress
    return get_delegate(self).keypress(size, key)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mvanderkamp/projects/pudb/venv/lib/python3.11/site-packages/urwid/widget/columns.py", line 1216, in keypress
    key = w.keypress(size_args[i], key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mvanderkamp/projects/pudb/pudb/ui_tools.py", line 131, in keypress
    result = self._w.keypress(size, key)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mvanderkamp/projects/pudb/venv/lib/python3.11/site-packages/urwid/widget/pile.py", line 921, in keypress
    key = self.focus.keypress(size_args[i], key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mvanderkamp/projects/pudb/venv/lib/python3.11/site-packages/urwid/widget/widget.py", line 729, in keypress
    return get_delegate(self).keypress(size, key)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mvanderkamp/projects/pudb/venv/lib/python3.11/site-packages/urwid/widget/pile.py", line 921, in keypress
    key = self.focus.keypress(size_args[i], key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mvanderkamp/projects/pudb/venv/lib/python3.11/site-packages/urwid/widget/widget.py", line 729, in keypress
    return get_delegate(self).keypress(size, key)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mvanderkamp/projects/pudb/pudb/ui_tools.py", line 136, in keypress
    return handler(self, size, key)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mvanderkamp/projects/pudb/pudb/debugger.py", line 997, in change_var_state
    pos = self.var_list._w.focus_position
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mvanderkamp/projects/pudb/venv/lib/python3.11/site-packages/urwid/widget/listbox.py", line 907, in _get_focus_position
    raise IndexError("No focus_position, ListBox is empty")
IndexError: No focus_position, ListBox is empty

The fix

Check for an IndexError when reading focus_position. From urwid:

property focus_position
the position of child widget in focus. The valid values for this position depend on the list walker in use. IndexError will be raised by reading this property when the ListBox is empty or setting this property to an invalid position.

@inducer inducer merged commit b0ea4cd into inducer:main Jun 5, 2024
8 checks passed
@inducer
Copy link
Owner

inducer commented Jun 5, 2024

Thanks!

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.

2 participants