Skip to content

Commit 788befd

Browse files
authored
tweak(fetch_objs): Raise ObjectDoesNotExist if object not found (#466)
2 parents a538072 + 3b8b27b commit 788befd

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ $ pip install --user --upgrade --pre libtmux
1414

1515
<!-- Maintainers and contributors: Insert change notes for the next release above -->
1616

17+
### Improvement
18+
19+
- `fetch_objs` now raises `ObjectDoesNotExist` with detailed information on
20+
lookup that failed (#466)
21+
1722
## libtmux 0.18.2 (2022-12-30)
1823

1924
### Fixes

src/libtmux/neo.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import typing as t
44

55
from libtmux import exc
6+
from libtmux._internal.query_list import ObjectDoesNotExist
67
from libtmux.common import tmux_cmd
78
from libtmux.formats import FORMAT_SEPARATOR
89

@@ -239,6 +240,12 @@ def fetch_obj(
239240
if _obj.get(obj_key) == obj_id:
240241
obj = _obj
241242

243+
if obj is None:
244+
raise ObjectDoesNotExist(
245+
f"Could not find {obj_key}={obj_id} for {list_cmd} "
246+
f'{list_extra_args if list_extra_args is not None else ""}'
247+
)
248+
242249
assert obj is not None
243250

244251
return obj

tests/test_window.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88

99
from libtmux import exc
10+
from libtmux._internal.query_list import ObjectDoesNotExist
1011
from libtmux.common import has_gte_version, has_lt_version
1112
from libtmux.pane import Pane
1213
from libtmux.server import Server
@@ -205,7 +206,7 @@ def test_kill_window(session: Session) -> None:
205206
w.window_id
206207

207208
w.kill_window()
208-
with pytest.raises(AssertionError): # TODO: Replace this will an object not found
209+
with pytest.raises(ObjectDoesNotExist):
209210
w.refresh()
210211

211212

0 commit comments

Comments
 (0)