Skip to content

Commit 9007db7

Browse files
committed
docs: Improve exc.py
1 parent 59b340f commit 9007db7

File tree

1 file changed

+45
-34
lines changed

1 file changed

+45
-34
lines changed

src/libtmux/exc.py

+45-34
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
"""libtmux exceptions.
1+
"""Provide exceptions used by libtmux.
22
33
libtmux.exc
44
~~~~~~~~~~~
55
6+
This module implements exceptions used throughout libtmux for error
7+
handling in sessions, windows, panes, and general usage. It preserves
8+
existing exception definitions for backward compatibility and does not
9+
remove any doctests.
10+
11+
Notes
12+
-----
13+
Exceptions in this module inherit from :exc:`LibTmuxException` or
14+
specialized base classes to form a hierarchy of tmux-related errors.
615
"""
716

817
from __future__ import annotations
@@ -16,19 +25,19 @@
1625

1726

1827
class LibTmuxException(Exception):
19-
"""Base Exception for libtmux Errors."""
28+
"""Base exception for all libtmux errors."""
2029

2130

2231
class TmuxSessionExists(LibTmuxException):
23-
"""Session does not exist in the server."""
32+
"""Raised if a tmux session with the requested name already exists."""
2433

2534

2635
class TmuxCommandNotFound(LibTmuxException):
27-
"""Application binary for tmux not found."""
36+
"""Raised when the tmux binary cannot be found on the system."""
2837

2938

3039
class TmuxObjectDoesNotExist(ObjectDoesNotExist):
31-
"""The query returned multiple objects when only one was expected."""
40+
"""Raised when a tmux object cannot be found in the server output."""
3241

3342
def __init__(
3443
self,
@@ -39,19 +48,20 @@ def __init__(
3948
*args: object,
4049
) -> None:
4150
if all(arg is not None for arg in [obj_key, obj_id, list_cmd, list_extra_args]):
42-
return super().__init__(
51+
super().__init__(
4352
f"Could not find {obj_key}={obj_id} for {list_cmd} "
4453
f"{list_extra_args if list_extra_args is not None else ''}",
4554
)
46-
return super().__init__("Could not find object")
55+
else:
56+
super().__init__("Could not find object")
4757

4858

4959
class VersionTooLow(LibTmuxException):
50-
"""Raised if tmux below the minimum version to use libtmux."""
60+
"""Raised if the installed tmux version is below the minimum required."""
5161

5262

5363
class BadSessionName(LibTmuxException):
54-
"""Disallowed session name for tmux (empty, contains periods or colons)."""
64+
"""Raised if a tmux session name is disallowed (e.g., empty, has colons/periods)."""
5565

5666
def __init__(
5767
self,
@@ -62,83 +72,84 @@ def __init__(
6272
msg = f"Bad session name: {reason}"
6373
if session_name is not None:
6474
msg += f" (session name: {session_name})"
65-
return super().__init__(msg)
75+
super().__init__(msg)
6676

6777

6878
class OptionError(LibTmuxException):
69-
"""Root error for any error involving invalid, ambiguous or bad options."""
79+
"""Base exception for errors involving invalid, ambiguous, or unknown options."""
7080

7181

7282
class UnknownOption(OptionError):
73-
"""Option unknown to tmux show-option(s) or show-window-option(s)."""
83+
"""Raised if tmux reports an unknown option."""
7484

7585

7686
class UnknownColorOption(UnknownOption):
77-
"""Unknown color option."""
87+
"""Raised if a server color option is unknown (must be 88 or 256)."""
7888

7989
def __init__(self, *args: object) -> None:
80-
return super().__init__("Server.colors must equal 88 or 256")
90+
super().__init__("Server.colors must equal 88 or 256")
8191

8292

8393
class InvalidOption(OptionError):
84-
"""Option invalid to tmux, introduced in tmux v2.4."""
94+
"""Raised if tmux reports an invalid option (tmux >= 2.4)."""
8595

8696

8797
class AmbiguousOption(OptionError):
88-
"""Option that could potentially match more than one."""
98+
"""Raised if tmux reports an option that could match more than one."""
8999

90100

91101
class WaitTimeout(LibTmuxException):
92-
"""Function timed out without meeting condition."""
102+
"""Raised when a function times out waiting for a condition."""
93103

94104

95105
class VariableUnpackingError(LibTmuxException):
96-
"""Error unpacking variable."""
106+
"""Raised when an environment variable cannot be unpacked as expected."""
97107

98108
def __init__(self, variable: t.Any | None = None, *args: object) -> None:
99-
return super().__init__(f"Unexpected variable: {variable!s}")
109+
super().__init__(f"Unexpected variable: {variable!s}")
100110

101111

102112
class PaneError(LibTmuxException):
103-
"""Any type of pane related error."""
113+
"""Base exception for pane-related errors."""
104114

105115

106116
class PaneNotFound(PaneError):
107-
"""Pane not found."""
117+
"""Raised if a specified pane cannot be found."""
108118

109119
def __init__(self, pane_id: str | None = None, *args: object) -> None:
110120
if pane_id is not None:
111-
return super().__init__(f"Pane not found: {pane_id}")
112-
return super().__init__("Pane not found")
121+
super().__init__(f"Pane not found: {pane_id}")
122+
else:
123+
super().__init__("Pane not found")
113124

114125

115126
class WindowError(LibTmuxException):
116-
"""Any type of window related error."""
127+
"""Base exception for window-related errors."""
117128

118129

119130
class MultipleActiveWindows(WindowError):
120-
"""Multiple active windows."""
131+
"""Raised if multiple active windows are detected (where only one is expected)."""
121132

122133
def __init__(self, count: int, *args: object) -> None:
123-
return super().__init__(f"Multiple active windows: {count} found")
134+
super().__init__(f"Multiple active windows: {count} found")
124135

125136

126137
class NoActiveWindow(WindowError):
127-
"""No active window found."""
138+
"""Raised if no active window exists when one is expected."""
128139

129140
def __init__(self, *args: object) -> None:
130-
return super().__init__("No active windows found")
141+
super().__init__("No active windows found")
131142

132143

133144
class NoWindowsExist(WindowError):
134-
"""No windows exist for object."""
145+
"""Raised if a session or server has no windows."""
135146

136147
def __init__(self, *args: object) -> None:
137-
return super().__init__("No windows exist for object")
148+
super().__init__("No windows exist for object")
138149

139150

140151
class AdjustmentDirectionRequiresAdjustment(LibTmuxException, ValueError):
141-
"""If *adjustment_direction* is set, *adjustment* must be set."""
152+
"""Raised if an adjustment direction is set, but no adjustment value is provided."""
142153

143154
def __init__(self) -> None:
144155
super().__init__("adjustment_direction requires adjustment")
@@ -148,18 +159,18 @@ class WindowAdjustmentDirectionRequiresAdjustment(
148159
WindowError,
149160
AdjustmentDirectionRequiresAdjustment,
150161
):
151-
"""ValueError for :meth:`libtmux.Window.resize_window`."""
162+
"""Raised if window resizing requires an adjustment value, but none is provided."""
152163

153164

154165
class PaneAdjustmentDirectionRequiresAdjustment(
155166
WindowError,
156167
AdjustmentDirectionRequiresAdjustment,
157168
):
158-
"""ValueError for :meth:`libtmux.Pane.resize_pane`."""
169+
"""Raised if pane resizing requires an adjustment value, but none is provided."""
159170

160171

161172
class RequiresDigitOrPercentage(LibTmuxException, ValueError):
162-
"""Requires digit (int or str digit) or a percentage."""
173+
"""Raised if a sizing argument must be a digit or a percentage."""
163174

164175
def __init__(self) -> None:
165176
super().__init__("Requires digit (int or str digit) or a percentage.")

0 commit comments

Comments
 (0)