{"record":{"id":"636d5e89c48ea7e6","repo":"jesseduffield/lazygit","slug":"errmsg","errorCode":null,"errorMessage":"{{errMsg}}","messagePattern":"\\{\\{errMsg\\}\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gui/controllers/helpers/repos_helper.go","lineNumber":231,"sourceCode":"// work tree (a dotfile repo opened with --git-dir/--work-tree, say) is the\n// reason we remember the environment at all: nothing in the path leads to its\n// git dir. On failure we put back what the repo we're staying in needs.\nfunc (self *ReposHelper) switchToLocation(location types.RepoLocation, errMsg string, contextKey types.ContextKey) error {\n\toriginalPath, err := os.Getwd()\n\tif err != nil {\n\t\treturn nil\n\t}\n\toriginalGitLocationEnvVars := env.GetGitLocationEnvVars()\n\n\tenv.SetGitLocationEnvVars(location.GitLocationEnvVars)\n\n\tmsg := utils.ResolvePlaceholderString(self.c.Tr.ChangingDirectoryTo, map[string]string{\"path\": location.Path})\n\tself.c.LogCommand(msg, false)\n\n\tif err := os.Chdir(location.Path); err != nil {\n\t\tenv.SetGitLocationEnvVars(originalGitLocationEnvVars)\n\t\tif os.IsNotExist(err) {\n\t\t\treturn errors.New(errMsg)\n\t\t}\n\t\treturn err\n\t}\n\n\tif err := commands.VerifyInGitRepo(self.c.OS()); err != nil {\n\t\tenv.SetGitLocationEnvVars(originalGitLocationEnvVars)\n\t\tif err := os.Chdir(originalPath); err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\treturn err\n\t}\n\n\tdirenvResult := self.logDirenvResult(direnv.Load(self.c.OS().Cmd))\n\n\tif err := self.recordDirectoryHelper.RecordCurrentDirectory(); err != nil {\n\t\tself.c.Log.Errorf(\"error recording current directory: %v\", err)\n\t}","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/helpers/repos_helper.go#L213-L249","documentation":"Returned by ReposHelper.switchToLocation when os.Chdir to the target repo path fails with fs.ErrNotExist: the recorded directory (recent repo, worktree path, or command-line arg) no longer exists on disk. The message itself is caller-supplied — each switchTo caller passes context (e.g. 'repo no longer exists' vs 'worktree no longer exists') — and non-NotExist chdir errors are returned raw. Env vars for git-dir/work-tree are restored before failing so the current session stays consistent.","triggerScenarios":"Selecting an entry from the recent-repos menu (pressing '/') or switching to a recorded worktree whose directory was deleted, renamed, or is on an unmounted drive; also stale paths in the state file after an external cleanup.","commonSituations":"Worktrees removed with 'git worktree remove' outside lazygit while still listed; repos moved or deleted; network-mounted paths temporarily unavailable; stale recent-repos list preserved across machines via dotfile sync.","solutions":["Verify the path exists: ls <path> in a shell.","If the repo/worktree was removed deliberately, remove it from lazygit's recent repos (delete the entry in the repos menu) so it stops being offered.","If moved, re-add the new location via 'open recent repo' -> add, or relaunch lazygit from the new path.","For unmounted network paths, remount and retry."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before switching:\nif _, err := os.Stat(path); os.IsNotExist(err) {\n    // prune the stale recent-repo/worktree entry instead of switching\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remove worktrees via lazygit so its records stay consistent","Prune deleted repos from the recent list when they are removed externally","os.Stat the recorded path before offering it in menus"],"tags":["filesystem","chdir","stale-path","recent-repos","worktrees"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}