From 5a6d5de3b8de89b1f1e412177d4bc0c7fa093267 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 2 Nov 2026 19:55:20 +0100 Subject: [PATCH] Start with the default app state if state.yml can't be parsed Several users on Windows reported that lazygit wouldn't start any more and failed with "yaml: control characters are not allowed" (#3023). Their state.yml was filled with zero bytes, most likely because the machine crashed or lost power shortly after lazygit had written the file. They had to find the file and delete it to make lazygit start again. Start with the defaults in this case. The file holds things like the shell command history and the recent repos list; losing them is better than not starting. The next save replaces the file. Co-Authored-By: Claude Opus 5.5 --- pkg/config/app_state.go | 6 +++++- pkg/config/app_state_test.go | 3 --- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/config/app_state.go b/pkg/config/app_state.go index 231d28d01..efa2e9757 100644 --- a/pkg/config/app_state.go +++ b/pkg/config/app_state.go @@ -58,7 +58,11 @@ func loadAppState() (*AppState, error) { err = yaml.Unmarshal(appStateBytes, appState) if err != nil { - return nil, err + // Nothing in state.yml is important enough to keep lazygit from + // starting. So if it can't be parsed (users have seen it filled with + // zero bytes after a crash), start with the defaults. The next save + // replaces the file. + return getDefaultAppState(), nil } return appState, nil diff --git a/pkg/config/app_state_test.go b/pkg/config/app_state_test.go index 5558d6b08..6236d08cc 100644 --- a/pkg/config/app_state_test.go +++ b/pkg/config/app_state_test.go @@ -31,8 +31,5 @@ func TestStartupWithBrokenAppStateFile(t *testing.T) { assert.NoError(t, err) _, err = newAppConfig(t) - /* EXPECTED: assert.NoError(t, err) - ACTUAL: */ - assert.ErrorContains(t, err, "control characters are not allowed") }