Skip to content

Commit e78fa2a

Browse files
committed
feat(exc): Add TmuxObjectDoesNotExist
1 parent ba23058 commit e78fa2a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/libtmux/exc.py

+24
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
"""
77
import typing as t
88

9+
from libtmux._internal.query_list import ObjectDoesNotExist
10+
11+
if t.TYPE_CHECKING:
12+
from libtmux.neo import ListExtraArgs
13+
914

1015
class LibTmuxException(Exception):
1116

@@ -22,6 +27,25 @@ class TmuxCommandNotFound(LibTmuxException):
2227
"""Application binary for tmux not found."""
2328

2429

30+
class TmuxObjectDoesNotExist(ObjectDoesNotExist):
31+
"""The query returned multiple objects when only one was expected."""
32+
33+
def __init__(
34+
self,
35+
obj_key: t.Optional[str] = None,
36+
obj_id: t.Optional[str] = None,
37+
list_cmd: t.Optional[str] = None,
38+
list_extra_args: "t.Optional[ListExtraArgs]" = None,
39+
*args: object,
40+
):
41+
if all(arg is not None for arg in [obj_key, obj_id, list_cmd, list_extra_args]):
42+
return super().__init__(
43+
f"Could not find {obj_key}={obj_id} for {list_cmd} "
44+
f'{list_extra_args if list_extra_args is not None else ""}'
45+
)
46+
return super().__init__("Could not find object")
47+
48+
2549
class VersionTooLow(LibTmuxException):
2650

2751
"""Raised if tmux below the minimum version to use libtmux."""

0 commit comments

Comments
 (0)