Skip to content

Commit ce9d20b

Browse files
committed
refactor(util): Consoidate get_{pane,window,session}
1 parent 1232510 commit ce9d20b

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/tmuxp/util.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,13 @@ def get_session(
116116
session = server.sessions.get(session_id=current_pane.session_id)
117117
else:
118118
session = server.sessions[0]
119-
except Exception:
120-
session = None
121119

122-
if session is None:
120+
except Exception as e:
123121
if session_name:
124-
raise exc.TmuxpException("Session not found: %s" % session_name)
125-
else:
126-
raise exc.TmuxpException("Session not found")
122+
raise exc.TmuxpException("Session not found: %s" % session_name) from e
123+
raise exc.TmuxpException("Session not found") from e
127124

125+
assert session is not None
128126
return session
129127

130128

@@ -140,17 +138,14 @@ def get_window(
140138
window = session.windows.get(window_id=current_pane.window_id)
141139
else:
142140
window = session.windows[0]
143-
except Exception:
144-
window = None
145-
146-
if window is None:
141+
except Exception as e:
147142
if window_name:
148-
raise exc.TmuxpException("Window not found: %s" % window_name)
143+
raise exc.TmuxpException("Window not found: %s" % window_name) from e
149144
if current_pane:
150-
raise exc.TmuxpException("Window not found: %s" % current_pane)
151-
else:
152-
raise exc.TmuxpException("Window not found")
145+
raise exc.TmuxpException("Window not found: %s" % current_pane) from e
146+
raise exc.TmuxpException("Window not found") from e
153147

148+
assert window is not None
154149
return window
155150

156151

0 commit comments

Comments
 (0)