Skip to content

Commit 27b3518

Browse files
committed
refactor(util): Use new NotFound exceptions, organize logic
1 parent ce9d20b commit 27b3518

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/tmuxp/util.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ def get_session(
119119

120120
except Exception as e:
121121
if session_name:
122-
raise exc.TmuxpException("Session not found: %s" % session_name) from e
123-
raise exc.TmuxpException("Session not found") from e
122+
raise exc.SessionNotFound(session_name) from e
123+
raise exc.SessionNotFound() from e
124124

125125
assert session is not None
126126
return session
@@ -140,10 +140,10 @@ def get_window(
140140
window = session.windows[0]
141141
except Exception as e:
142142
if window_name:
143-
raise exc.TmuxpException("Window not found: %s" % window_name) from e
144-
if current_pane:
145-
raise exc.TmuxpException("Window not found: %s" % current_pane) from e
146-
raise exc.TmuxpException("Window not found") from e
143+
raise exc.WindowNotFound(window_target=window_name) from e
144+
elif current_pane:
145+
raise exc.WindowNotFound(window_target=str(current_pane)) from e
146+
raise exc.WindowNotFound() from e
147147

148148
assert window is not None
149149
return window
@@ -161,8 +161,7 @@ def get_pane(window: "Window", current_pane: t.Optional["Pane"] = None) -> "Pane
161161

162162
if pane is None:
163163
if current_pane:
164-
raise exc.TmuxpException("Pane not found: %s" % current_pane)
165-
else:
166-
raise exc.TmuxpException("Pane not found")
164+
raise exc.PaneNotFound(str(current_pane))
165+
raise exc.PaneNotFound()
167166

168167
return pane

0 commit comments

Comments
 (0)