{"record":{"id":"30fb82b18ea78950","repo":"jesseduffield/lazygit","slug":"new-key-s-already-exists","errorCode":null,"errorMessage":"new key `%s' already exists","messagePattern":"new key `(.+?)' already exists","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/utils/yaml_utils/yaml_utils.go","lineNumber":111,"sourceCode":"\treturn renameYamlKey(body, path, newKey)\n}\n\n// Recursive function to rename the YAML key.\nfunc renameYamlKey(node *yaml.Node, path []string, newKey string) (error, bool) {\n\tif node.Kind != yaml.MappingNode {\n\t\treturn errors.New(\"yaml node in path is not a dictionary\"), false\n\t}\n\n\tkeyNode, valueNode := LookupKey(node, path[0])\n\tif keyNode == nil {\n\t\treturn nil, false\n\t}\n\n\t// end of path reached: rename key\n\tif len(path) == 1 {\n\t\t// Check that new key doesn't exist yet\n\t\tif newKeyNode, _ := LookupKey(node, newKey); newKeyNode != nil {\n\t\t\treturn fmt.Errorf(\"new key `%s' already exists\", newKey), false\n\t\t}\n\n\t\tkeyNode.Value = newKey\n\t\treturn nil, true\n\t}\n\n\treturn renameYamlKey(valueNode, path[1:], newKey)\n}\n\n// Takes the root node of a yaml document, the path to an existing key, and the\n// path at which it should live instead. If the key exists, it (and its value)\n// is moved to the new path, creating intermediate mapping nodes as needed, and\n// any mapping nodes left empty behind it are removed. Does nothing if the key\n// at oldPath doesn't exist. Returns an error if a key already exists at newPath,\n// or if a node along either path exists but isn't a mapping.\nfunc MoveYamlKey(rootNode *yaml.Node, oldPath []string, newPath []string) (error, bool) {\n\t// Empty document: nothing to do.\n\tif len(rootNode.Content) == 0 {","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/utils/yaml_utils/yaml_utils.go#L93-L129","documentation":"Returned by RenameKeyPaths/renameYamlKey in pkg/utils/yaml_utils when renaming a key inside a YAML document (lazygit's config migration machinery) and the target name already exists as a sibling key in the same mapping. The rename is aborted to avoid overwriting an existing key's value.","triggerScenarios":"A config migration renaming e.g. gui.<oldKey> to gui.<newKey> when config.yml already contains gui.<newKey> with its own value; LookupKey(node, newKey) finds a non-nil key node at the same level.","commonSituations":"A user already set the new-style key in config.yml before upgrading, then lazygit's version migration tries to rename the old key on top of it; hand-merged configs containing both old and new names; running an older lazygit binary against a config already migrated by a newer one, then upgrading again.","solutions":["Open config.yml, find the mapping named in the error, and delete either the old key (keep your new-key value) or the new key (keep the old one so migration can complete)","Re-run lazygit so the migration applies cleanly once no collision exists","Prefer resolving manually over ignoring — the migration refuses to pick a winner for you"],"exampleFix":"# before (both keys present, migration fails)\ngui:\n  oldTimeFormat: '2006-01-02'\n  timeFormat: '2006-01-02'\n\n# after (remove legacy key)\ngui:\n  timeFormat: '2006-01-02'","handlingStrategy":"validation","validationCode":"# before migrating, check the rename target doesn't already exist as a sibling\nyq '.gui | to_entries | map(.key) | .[]' ~/.config/lazygit/config.yml","typeGuard":null,"tryCatchPattern":"Catch the rename error, keep the value you want by editing config.yml manually, and re-run the migration; never overwrite the pre-existing key programmatically.","preventionTips":["Don't pre-add new-style config keys before the version that introduces them","Keep a backup of config.yml across upgrades so collisions are diffable"],"tags":["lazygit","yaml","config-migration","key-rename"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}