Skip to content
Prev Previous commit
Next Next commit
feat(exc): Add TmuxObjectDoesNotExist
  • Loading branch information
tony committed Aug 20, 2023
commit 5ede0f71019854f5025f15faf59e614ca131394c
24 changes: 24 additions & 0 deletions src/libtmux/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
"""
import typing as t

from libtmux._internal.query_list import ObjectDoesNotExist

if t.TYPE_CHECKING:
from libtmux.neo import ListExtraArgs


class LibTmuxException(Exception):

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


class TmuxObjectDoesNotExist(ObjectDoesNotExist):
"""The query returned multiple objects when only one was expected."""

def __init__(
self,
obj_key: t.Optional[str] = None,
obj_id: t.Optional[str] = None,
list_cmd: t.Optional[str] = None,
list_extra_args: "t.Optional[ListExtraArgs]" = None,
*args: object,
):
if all(arg is not None for arg in [obj_key, obj_id, list_cmd, list_extra_args]):
return super().__init__(
f"Could not find {obj_key}={obj_id} for {list_cmd} "
f'{list_extra_args if list_extra_args is not None else ""}'
)
return super().__init__("Could not find object")


class VersionTooLow(LibTmuxException):

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