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 <noreply@anthropic.com>
This commit is contained in:
Stefan HallerandClaude Opus 5.5 committed 2026-11-15 08:10:58 +01:00
1 parent 2d270f0e54
commit 5a6d5de3b8
2 files changed
+5 -4

No files matched your search

+5 -1
View File
@@ -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
-3
View File
@@ -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")
}