Skip to content

Commit 6041e66

Browse files
committed
libtmux(fix[logging]): guard None values in server/session extra dicts
why: session_id and session_name can be None (str | None), violating the logging standard that extra values must be str at INFO+ level. what: - session.py rename_session: use conditional-build pattern for tmux_target - server.py new_session DEBUG log: conditional tmux_session - server.py new_session INFO log: conditional tmux_session
1 parent cf55c3f commit 6041e66

2 files changed

Lines changed: 19 additions & 22 deletions

File tree

src/libtmux/server.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,12 @@ def new_session(
538538
msg,
539539
)
540540

541-
logger.debug(
542-
"creating session",
543-
extra={
544-
"tmux_session": session_name,
545-
"tmux_subcommand": "new-session",
546-
},
547-
)
541+
extra: dict[str, str] = {
542+
"tmux_subcommand": "new-session",
543+
}
544+
if session_name is not None:
545+
extra["tmux_session"] = str(session_name)
546+
logger.debug("creating session", extra=extra)
548547

549548
env = os.environ.get("TMUX")
550549

@@ -600,13 +599,12 @@ def new_session(
600599

601600
session = Session(server=self, **session_data)
602601

603-
logger.info(
604-
"session created",
605-
extra={
606-
"tmux_subcommand": "new-session",
607-
"tmux_session": session.session_name,
608-
},
609-
)
602+
info_extra: dict[str, str] = {
603+
"tmux_subcommand": "new-session",
604+
}
605+
if session.session_name is not None:
606+
info_extra["tmux_session"] = str(session.session_name)
607+
logger.info("session created", extra=info_extra)
610608

611609
return session
612610

src/libtmux/session.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,14 +439,13 @@ def rename_session(self, new_name: str) -> Session:
439439

440440
self.refresh()
441441

442-
logger.info(
443-
"session renamed",
444-
extra={
445-
"tmux_subcommand": "rename-session",
446-
"tmux_session": new_name,
447-
"tmux_target": self.session_id,
448-
},
449-
)
442+
extra: dict[str, str] = {
443+
"tmux_subcommand": "rename-session",
444+
"tmux_session": new_name,
445+
}
446+
if self.session_id is not None:
447+
extra["tmux_target"] = str(self.session_id)
448+
logger.info("session renamed", extra=extra)
450449

451450
return self
452451

0 commit comments

Comments
 (0)