diff --git a/CHANGES b/CHANGES index 22ba40208..060348fc9 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,11 @@ $ pip install --user --upgrade --pre libtmux +### Improvement + +- `fetch_objs` now raises `ObjectDoesNotExist` with detailed information on + lookup that failed (#466) + ## libtmux 0.18.2 (2022-12-30) ### Fixes diff --git a/src/libtmux/neo.py b/src/libtmux/neo.py index be1621214..70267b07d 100644 --- a/src/libtmux/neo.py +++ b/src/libtmux/neo.py @@ -3,6 +3,7 @@ import typing as t from libtmux import exc +from libtmux._internal.query_list import ObjectDoesNotExist from libtmux.common import tmux_cmd from libtmux.formats import FORMAT_SEPARATOR @@ -239,6 +240,12 @@ def fetch_obj( if _obj.get(obj_key) == obj_id: obj = _obj + if obj is None: + raise ObjectDoesNotExist( + f"Could not find {obj_key}={obj_id} for {list_cmd} " + f'{list_extra_args if list_extra_args is not None else ""}' + ) + assert obj is not None return obj diff --git a/tests/test_window.py b/tests/test_window.py index 1401bf2fe..aa9a1cd6a 100644 --- a/tests/test_window.py +++ b/tests/test_window.py @@ -7,6 +7,7 @@ import pytest from libtmux import exc +from libtmux._internal.query_list import ObjectDoesNotExist from libtmux.common import has_gte_version, has_lt_version from libtmux.pane import Pane from libtmux.server import Server @@ -205,7 +206,7 @@ def test_kill_window(session: Session) -> None: w.window_id w.kill_window() - with pytest.raises(AssertionError): # TODO: Replace this will an object not found + with pytest.raises(ObjectDoesNotExist): w.refresh()