{"record":{"id":"4ff05d32c54228da","repo":"jesseduffield/lazygit","slug":"while-attempting-to-write-back-migrated-user-confi","errorCode":null,"errorMessage":"While attempting to write back migrated user config to %s, an error occurred: %s","messagePattern":"While attempting to write back migrated user config to (.+?), an error occurred: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/config/app_config.go","lineNumber":268,"sourceCode":"\t\treturn content, nil\n\t}\n\n\tchangesText := \"The following changes were made:\\n\\n\"\n\tchangesText += strings.Join(lo.Map(changes.ToSliceFromOldest(), func(change string, _ int) string {\n\t\treturn fmt.Sprintf(\"- %s\\n\", change)\n\t}), \"\")\n\n\t// Write config back\n\tif !isGuiInitialized {\n\t\tfmt.Printf(\"The user config file %s must be migrated. Attempting to do this automatically.\\n\", path)\n\t\tfmt.Println(changesText)\n\t}\n\tif err := os.WriteFile(path, changedContent, 0o644); err != nil {\n\t\terrorMsg := fmt.Sprintf(\"While attempting to write back migrated user config to %s, an error occurred: %s\", path, err)\n\t\tif isGuiInitialized {\n\t\t\terrorMsg += \"\\n\\n\" + changesText\n\t\t}\n\t\treturn nil, errors.New(errorMsg)\n\t}\n\tif !isGuiInitialized {\n\t\tfmt.Printf(\"Config file saved successfully to %s\\n\", path)\n\t}\n\treturn changedContent, nil\n}\n\n// A pure function helper for testing purposes\nfunc computeMigratedConfig(path string, content []byte, changes *ChangesSet) ([]byte, bool, error) {\n\tvar err error\n\tvar rootNode yaml.Node\n\terr = yaml.Unmarshal(content, &rootNode)\n\tif err != nil {\n\t\treturn nil, false, fmt.Errorf(\"failed to parse YAML: %w\", err)\n\t}\n\tvar originalCopy yaml.Node\n\terr = yaml.Unmarshal(content, &originalCopy)\n\tif err != nil {","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/config/app_config.go#L250-L286","documentation":"Raised in pkg/config/app_config.go:268 during automatic user config migration. lazygit detected that the config file needs a schema migration, computed the migrated YAML content, but os.WriteFile to the config path failed (permissions, missing parent dir, read-only filesystem). The error includes the path and the underlying write error; in GUI mode the pending changes text is appended so the user can apply it manually.","triggerScenarios":"os.WriteFile(path, changedContent, 0o644) failing: config dir owned by another user, config on a read-only mount, disk full, SELinux/AppArmor denial, or the file being immutable.","commonSituations":"Running lazygit with sudo previously so ~/.config/lazygit is root-owned; corporate machines with enforced read-only home subpaths; config synced via a tool that locks the file; upgrading lazygit across a version that introduced a config migration.","solutions":["Fix ownership/permissions: 'chown -R $USER ~/.config/lazygit' and ensure write access (chmod u+w)","Free disk space or remount the config location read-write","Re-run lazygit from a terminal (isGuiInitialized=false) so the changes text prints to stdout, and apply the migration by hand","Back up then delete the stale config so lazygit regenerates defaults, then reapply custom settings"],"exampleFix":"# shell fix, not a code fix\nsudo chown -R $(whoami) ~/.config/lazygit\nchmod u+w ~/.config/lazygit/config.yml","handlingStrategy":"validation","validationCode":"// Pre-flight check before launching lazygit across an upgrade:\nfunc configWritable(path string) error {\n    info, err := os.Stat(filepath.Dir(path))\n    if err != nil {\n        return err\n    }\n    if info.Mode().Perm()&0o200 == 0 {\n        return fmt.Errorf(\"config dir %s is not writable\", filepath.Dir(path))\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if _, err := loadConfig(); err != nil && strings.Contains(err.Error(), \"write back migrated user config\") {\n    // apply printed changesText manually after fixing permissions\n    fmt.Println(err)\n}","preventionTips":["Never run lazygit under sudo; fix ownership with chown if you did","Keep the config dir writable and backed up before upgrades","Run lazygit in a terminal when migrating so changesText prints for manual recovery"],"tags":["config","filesystem","migration","permissions"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}