{"record":{"id":"e5f2c1f3dc431f8f","repo":"oraios/serena","slug":"multiple-projects-found-with-name-project-root-o","errorCode":null,"errorMessage":"Multiple projects found with name '{project_root_or_name}'. Please reference it by location instead. Locations: {[p.project_root for p in project_candidates]}","messagePattern":"Multiple projects found with name '(.+?)'\\. Please reference it by location instead\\. Locations: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/serena/config/serena_config.py","lineNumber":1217,"sourceCode":"    def project_names(self) -> list[str]:\n        return sorted(project.project_config.project_name for project in self.projects)\n\n    def get_registered_project(self, project_root_or_name: str, autoregister: bool = False) -> Optional[RegisteredProject]:\n        \"\"\"\n        :param project_root_or_name: path to the project root or the name of the project\n        :param autoregister: whether to auto-register projects that are not yet registered in Serena's global configuration\n            but have an existing project configuration file. Project configuration files are never auto-generated.\n        :return: the registered project, or None if not found\n        \"\"\"\n        # look for project by name\n        project_candidates = []\n        for project in self.projects:\n            if project.project_config.project_name == project_root_or_name:\n                project_candidates.append(project)\n        if len(project_candidates) == 1:\n            return project_candidates[0]\n        elif len(project_candidates) > 1:\n            raise ValueError(\n                f\"Multiple projects found with name '{project_root_or_name}'. Please reference it by location instead. \"\n                f\"Locations: {[p.project_root for p in project_candidates]}\"\n            )\n        # no project found by name; check if it's a path\n        if os.path.isdir(project_root_or_name):\n            for project in self.projects:\n                if project.matches_root_path(project_root_or_name):\n                    return project\n        # no registered project found; optionally auto-register if a project configuration already exists\n        if autoregister:\n            config_path = self.get_project_yml_location(project_root_or_name)\n            if os.path.isfile(config_path):\n                registered_project = RegisteredProject.from_project_root(project_root_or_name, serena_config=self)\n                self.add_registered_project(registered_project)\n                return registered_project\n        # nothing found\n        return None\n","sourceCodeStart":1199,"sourceCodeEnd":1235,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/serena/config/serena_config.py#L1199-L1235","documentation":"get_registered_project() resolves a project either by root path or by name. When the given string matches the project_name of more than one registered project, resolution is ambiguous, so it raises ValueError listing all matching roots and asks the caller to reference the project by its location instead.","triggerScenarios":"Calling get_registered_project('myproj') (directly or via activate_project_from_path_or_name / get_project) when two different directories are registered with the same project_name in their serena_project.yml files.","commonSituations":"Cloning the same repo to two folders (both ymls keep the identical project_name); forking a project without renaming; copying a project directory and its config; team-shared configs registering duplicate names.","solutions":["Call with the project's absolute path instead of the name: get_registered_project('/path/to/repo').","Edit one of the duplicate serena_project.yml files to give it a unique project_name.","Remove the redundant registration with SerenaConfig.remove_project(name-or-path) and re-add the correct one via add_project_from_path."],"exampleFix":"// before\nproject = config.get_registered_project('myproj')  # ambiguous\n// after\nproject = config.get_registered_project('/home/me/work/myproj')","handlingStrategy":"try-catch","validationCode":"names = [p.project_config.project_name for p in config.projects]\nambiguous = name in names and names.count(name) > 1","typeGuard":"def is_unambiguous_name(config, name: str) -> bool:\n    names = [p.project_config.project_name for p in config.projects]\n    return names.count(name) <= 1 or name in config.project_names","tryCatchPattern":"try:\n    project = config.get_registered_project('myproj')\nexcept ValueError as e:\n    if 'Multiple projects found' in str(e):\n        project = config.get_registered_project('/abs/path/to/myproj')\n    else:\n        raise","preventionTips":["Give every registered project a unique project_name in its serena_project.yml","Reference projects by absolute path in scripts instead of by name","Rename duplicates after cloning/forking a repo"],"tags":["configuration","ambiguous-name","python"],"backgroundTag":"ambiguous-identifier","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}