From 70d8a536f1c0eb965c2fa52076532fe52f08ef60 Mon Sep 17 00:00:00 2001 From: James Swartz Date: Fri, 18 Sep 2026 14:14:25 -0400 Subject: [PATCH] Fix Kitty crashing on startup when disk is full --- kitty/boss.py | 3 ++- kitty/config.py | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index 7228de459..d4e1f5eba 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -463,7 +463,8 @@ class Boss: set_boss(self) self.mappings: Mappings = Mappings(global_shortcuts, self.refresh_active_tab_bar) self.notification_manager: NotificationManager = NotificationManager(debug=self.args.debug_keyboard or self.args.debug_rendering) - self.atexit.unlink(store_effective_config()) + if effective_config_path := store_effective_config(): + self.atexit.unlink(effective_config_path) def startup_first_child(self, os_window_id: int | None, startup_sessions: Iterable[Session] = ()) -> None: si = startup_sessions or create_sessions(get_options(), self.args, default_session=get_options().startup_session) diff --git a/kitty/config.py b/kitty/config.py index d18325b5d..58ea0648a 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -207,14 +207,21 @@ def store_effective_config() -> str: import stat import tempfile - dest = os.path.join(cache_dir(), 'effective-config') - os.makedirs(dest, exist_ok=True) - raw = '\n'.join(effective_config_lines) - with suppress(FileNotFoundError), tempfile.NamedTemporaryFile('w', dir=dest) as tf: - os.chmod(tf.name, stat.S_IRUSR | stat.S_IWUSR) - print(raw, file=tf) - path = os.path.join(dest, f'{os.getpid()}') - os.replace(tf.name, path) + path = '' + try: + dest = os.path.join(cache_dir(), 'effective-config') + os.makedirs(dest, exist_ok=True) + raw = '\n'.join(effective_config_lines) + with suppress(FileNotFoundError), tempfile.NamedTemporaryFile('w', dir=dest) as tf: + os.chmod(tf.name, stat.S_IRUSR | stat.S_IWUSR) + print(raw, file=tf) + path = os.path.join(dest, f'{os.getpid()}') + os.replace(tf.name, path) + except OSError as err: + # writing the effective config is a best effort debugging aid, do not + # let it prevent kitty from starting, for example, when the disk is full + log_error(f'Failed to store effective config with error: {err}') + path = '' return path