1
- """libtmux exceptions.
1
+ """Provide exceptions used by libtmux .
2
2
3
3
libtmux.exc
4
4
~~~~~~~~~~~
5
5
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.
6
15
"""
7
16
8
17
from __future__ import annotations
16
25
17
26
18
27
class LibTmuxException (Exception ):
19
- """Base Exception for libtmux Errors ."""
28
+ """Base exception for all libtmux errors ."""
20
29
21
30
22
31
class TmuxSessionExists (LibTmuxException ):
23
- """Session does not exist in the server ."""
32
+ """Raised if a tmux session with the requested name already exists ."""
24
33
25
34
26
35
class TmuxCommandNotFound (LibTmuxException ):
27
- """Application binary for tmux not found."""
36
+ """Raised when the tmux binary cannot be found on the system ."""
28
37
29
38
30
39
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 ."""
32
41
33
42
def __init__ (
34
43
self ,
@@ -39,19 +48,20 @@ def __init__(
39
48
* args : object ,
40
49
) -> None :
41
50
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__ (
43
52
f"Could not find { obj_key } ={ obj_id } for { list_cmd } "
44
53
f"{ list_extra_args if list_extra_args is not None else '' } " ,
45
54
)
46
- return super ().__init__ ("Could not find object" )
55
+ else :
56
+ super ().__init__ ("Could not find object" )
47
57
48
58
49
59
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 ."""
51
61
52
62
53
63
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 )."""
55
65
56
66
def __init__ (
57
67
self ,
@@ -62,83 +72,84 @@ def __init__(
62
72
msg = f"Bad session name: { reason } "
63
73
if session_name is not None :
64
74
msg += f" (session name: { session_name } )"
65
- return super ().__init__ (msg )
75
+ super ().__init__ (msg )
66
76
67
77
68
78
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."""
70
80
71
81
72
82
class UnknownOption (OptionError ):
73
- """Option unknown to tmux show-option(s) or show-window- option(s) ."""
83
+ """Raised if tmux reports an unknown option."""
74
84
75
85
76
86
class UnknownColorOption (UnknownOption ):
77
- """Unknown color option."""
87
+ """Raised if a server color option is unknown (must be 88 or 256) ."""
78
88
79
89
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" )
81
91
82
92
83
93
class InvalidOption (OptionError ):
84
- """Option invalid to tmux, introduced in tmux v2.4 ."""
94
+ """Raised if tmux reports an invalid option ( tmux >= 2.4) ."""
85
95
86
96
87
97
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."""
89
99
90
100
91
101
class WaitTimeout (LibTmuxException ):
92
- """Function timed out without meeting condition."""
102
+ """Raised when a function times out waiting for a condition."""
93
103
94
104
95
105
class VariableUnpackingError (LibTmuxException ):
96
- """Error unpacking variable."""
106
+ """Raised when an environment variable cannot be unpacked as expected ."""
97
107
98
108
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} " )
100
110
101
111
102
112
class PaneError (LibTmuxException ):
103
- """Any type of pane related error ."""
113
+ """Base exception for pane- related errors ."""
104
114
105
115
106
116
class PaneNotFound (PaneError ):
107
- """Pane not found."""
117
+ """Raised if a specified pane cannot be found."""
108
118
109
119
def __init__ (self , pane_id : str | None = None , * args : object ) -> None :
110
120
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" )
113
124
114
125
115
126
class WindowError (LibTmuxException ):
116
- """Any type of window related error ."""
127
+ """Base exception for window- related errors ."""
117
128
118
129
119
130
class MultipleActiveWindows (WindowError ):
120
- """Multiple active windows."""
131
+ """Raised if multiple active windows are detected (where only one is expected) ."""
121
132
122
133
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" )
124
135
125
136
126
137
class NoActiveWindow (WindowError ):
127
- """No active window found ."""
138
+ """Raised if no active window exists when one is expected ."""
128
139
129
140
def __init__ (self , * args : object ) -> None :
130
- return super ().__init__ ("No active windows found" )
141
+ super ().__init__ ("No active windows found" )
131
142
132
143
133
144
class NoWindowsExist (WindowError ):
134
- """No windows exist for object ."""
145
+ """Raised if a session or server has no windows ."""
135
146
136
147
def __init__ (self , * args : object ) -> None :
137
- return super ().__init__ ("No windows exist for object" )
148
+ super ().__init__ ("No windows exist for object" )
138
149
139
150
140
151
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 ."""
142
153
143
154
def __init__ (self ) -> None :
144
155
super ().__init__ ("adjustment_direction requires adjustment" )
@@ -148,18 +159,18 @@ class WindowAdjustmentDirectionRequiresAdjustment(
148
159
WindowError ,
149
160
AdjustmentDirectionRequiresAdjustment ,
150
161
):
151
- """ValueError for :meth:`libtmux.Window.resize_window` ."""
162
+ """Raised if window resizing requires an adjustment value, but none is provided ."""
152
163
153
164
154
165
class PaneAdjustmentDirectionRequiresAdjustment (
155
166
WindowError ,
156
167
AdjustmentDirectionRequiresAdjustment ,
157
168
):
158
- """ValueError for :meth:`libtmux.Pane.resize_pane` ."""
169
+ """Raised if pane resizing requires an adjustment value, but none is provided ."""
159
170
160
171
161
172
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."""
163
174
164
175
def __init__ (self ) -> None :
165
176
super ().__init__ ("Requires digit (int or str digit) or a percentage." )
0 commit comments