Specific exceptions raising if pane or window manually closed

Open
#340 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
api, cli

Research direction

The traceback points to libtmux/pane.py (_info and send_keys) and libtmux/window.py (_info and kill_window); start there and reproduce each operation after its pane or window is manually closed. Done means these cases raise specific exceptions instead of IndexError.

Written by the indexing model from the issue text.

Description

Specific exceptions should be raised in some cases.

For example, if we send keys to a previously attached pane of a window, but the window is manually closed while the program is running, this hapens:

Traceback (most recent call last)
[...]
 File "/usr/share//class_tmuxserver.py", line 78, in create_or_clear_window
    self.dict_panes[window_name]["pane_cmd"].send_keys('C-c', enter=False, suppress_history=False)

  File "/usr/share//venv/lib/python3.8/site-packages/libtmux/pane.py", line 117, in send_keys
    self.cmd('send-keys', prefix + cmd)
  File "/usr/share//venv/lib/python3.8/site-packages/libtmux/pane.py", line 90, in cmd
    args = ('-t', self.get('pane_id')) + args
  File "/usr/local/lib/python3.8/_collections_abc.py", line 660, in get
    return self[key]
  File "/usr/share//venv/lib/python3.8/site-packages/libtmux/common.py", line 251, in __getitem__
    return self._info[key]
  File "/usr/share//venv/lib/python3.8/site-packages/libtmux/pane.py", line 75, in _info
    return list(filter(by, self.server._panes))[0]
`IndexError: list index out of range`

Same thing if we try to kill a window which was manually closed in the tmux:

Traceback (most recent call last)
 [...]
  File "/home/admin//src/class_tmuxserver.py", line 116, in kill_tmux_window
    self.dict_windows[window_name].kill_window()
  File "/home/admin//venv/lib64/python3.7/site-packages/libtmux/window.py", line 308, in kill_window
    '-t%s:%s' % (self.get('session_id'), self.index),
  File "/usr/lib64/python3.7/_collections_abc.py", line 660, in get
    return self[key]
  File "/home/admin//venv/lib64/python3.7/site-packages/libtmux/common.py", line 252, in __getitem__
    return self._info[key]
  File "/home/admin//venv/lib64/python3.7/site-packages/libtmux/window.py", line 89, in _info
    return ret[0]
IndexError: list index out of range
Dominant language
Python
Stars
1.2k
Forks
127
Avg merge
2h 13m
Merged PRs (30d)
1

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.

More from tmux-python/libtmux

All issues in tmux-python/libtmux

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.