{"record":{"id":"8de8d7072a4dd281","repo":"gitbutlerapp/gitbutler","slug":"project-already-exists","errorCode":null,"errorMessage":"project already exists","messagePattern":"project already exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-project/src/project.rs","lineNumber":318,"sourceCode":"}\n\nimpl AddProjectOutcome {\n    /// This is for tests only.\n    ///\n    /// Unwraps the `Project` if the project was actually added.\n    /// Panics if it was not.\n    pub fn unwrap_project(self) -> Project {\n        match self {\n            AddProjectOutcome::Added(p) => p,\n            _ => panic!(\"called `AddProjectOutcome::unwrap_project()` on a non-project outcome\"),\n        }\n    }\n\n    /// Try to get the `Project`, returning an error if it was not added.\n    pub fn try_project(self) -> anyhow::Result<Project> {\n        match self {\n            AddProjectOutcome::Added(p) => Ok(p),\n            AddProjectOutcome::AlreadyExists(_) => Err(anyhow::anyhow!(\"project already exists\")),\n            AddProjectOutcome::PathNotFound => Err(anyhow::anyhow!(\"project path not found\")),\n            AddProjectOutcome::NotADirectory => {\n                Err(anyhow::anyhow!(\"project path is not a directory\"))\n            }\n            AddProjectOutcome::BareRepository => {\n                Err(anyhow::anyhow!(\"bare repositories are not supported\"))\n            }\n            AddProjectOutcome::NonMainWorktree => {\n                Err(anyhow::anyhow!(\"non-main worktrees are not supported\"))\n            }\n            AddProjectOutcome::NoWorkdir => Err(anyhow::anyhow!(\"no workdir found for repository\")),\n            AddProjectOutcome::NoDotGitDirectory => {\n                Err(anyhow::anyhow!(\"no .git directory found in repository\"))\n            }\n            AddProjectOutcome::ReftableRefFormatUnsupported => Err(anyhow::anyhow!(\n                \"unsupported repository reference format: reftable\"\n            )),\n            AddProjectOutcome::NotAGitRepository(msg) => {","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-project/src/project.rs#L300-L336","documentation":"try_project converts an AddProjectOutcome into a Project or an error. The AlreadyExists variant means the path is already registered as a project in GitButler, so adding it again is rejected with this error. The original Project is carried in the variant but discarded by this conversion.","triggerScenarios":"Calling try_project on an outcome returned by the add-project flow when the worktree path was previously added (AddProjectOutcome::AlreadyExists) — i.e. a duplicate add of the same directory.","commonSituations":"Users dragging the same folder into GitButler twice, automation re-running an add script, or re-adding a project after list refresh without checking existence.","solutions":["Don't re-add: fetch the existing project from the project list instead (the AlreadyExists variant carries the existing Project — use it directly rather than calling try_project).","Check whether the path is already registered before adding (list projects and compare worktree paths).","If a stale duplicate entry is the issue, remove the old project entry and add again."],"exampleFix":"// before\nlet project = outcome.try_project()?;\n// after\nmatch outcome {\n    AddProjectOutcome::Added(p) => Ok(p),\n    AddProjectOutcome::AlreadyExists(p) => Ok(p), // reuse existing\n    other => other.try_project(),\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fn project_added(outcome: &AddProjectOutcome) -> bool {\n    matches!(outcome, AddProjectOutcome::Added(_) | AddProjectOutcome::AlreadyExists(_))\n}","tryCatchPattern":"match add_outcome {\n    Err(e) if e.to_string() == \"project already exists\" => {\n        // fetch existing project by path and continue\n        get_existing_project_by_path(path)?\n    }\n    other => other,\n}","preventionTips":["Check the project list for the path before calling add-project.","Reuse the Project carried by AddProjectOutcome::AlreadyExists instead of erroring.","Make add-project calls idempotent in scripts/automation."],"tags":["project","duplicate","registration"],"backgroundTag":"file-already-exists","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}