{"record":{"id":"42c77a6614db1992","repo":"abhigyanpatwari/GitNexus","slug":"group-path-grouppath-is-already-mapped-to-con","errorCode":null,"errorMessage":"group path ${groupPath} is already mapped to ${config.repos[groupPath]}","messagePattern":"group path (.+?) is already mapped to (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/auto-sync/runner.ts","lineNumber":409,"sourceCode":"  repoName: string,\n  remoteUrl?: string,\n): string {\n  if (!remoteUrl) return path.resolve(project.localPath, repoName);\n  const identity = getAutoSyncRepoIdentity(remoteUrl);\n  return path.resolve(project.localPath, ...identity.split('/').slice(0, -1), repoName);\n}\n\nexport async function addRepoToGroup(\n  project: Pick<AutoSyncProjectConfig, 'groupName'>,\n  groupPath: string,\n  registryName = groupPath,\n): Promise<boolean> {\n  if (!project.groupName) return false;\n  const groupDir = getGroupDir(getDefaultGitnexusDir(), project.groupName);\n  const config = await loadGroupConfig(groupDir);\n  if (config.repos[groupPath] === registryName) return false;\n  if (config.repos[groupPath] !== undefined) {\n    throw new Error(`group path ${groupPath} is already mapped to ${config.repos[groupPath]}`);\n  }\n  config.repos[groupPath] = registryName;\n  await writeGroupConfigAtomic(path.join(groupDir, 'group.yaml'), config);\n  return true;\n}\n\nexport function getAutoSyncRepoIdentity(remoteUrl: string): string {\n  validateAutoSyncRemoteUrl(remoteUrl);\n  const [, host, remotePath] = /^git@([^:\\s/]+):([^\\s]+)$/.exec(remoteUrl.trim())!;\n  return `${host.toLowerCase()}/${remotePath.replace(/\\.git$/i, '')}`;\n}\n\nexport async function syncGroupByName(groupName: string): Promise<void> {\n  const groupDir = getGroupDir(getDefaultGitnexusDir(), groupName);\n  const config = await loadGroupConfig(groupDir);\n  await syncGroup(config, { groupDir });\n}\n","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/0d1aed942f0e8b5d3bac27519fff441aceea722d/gitnexus/src/core/auto-sync/runner.ts#L391-L427","documentation":"addRepoToGroup refuses to overwrite an existing mapping in a group's group.yaml. Each repo path in an auto-sync group may map to exactly one registry name; if the path is already mapped to a different name, the mapping is treated as conflicting and thrown rather than silently overwritten. If the path is already mapped to the SAME registry name, the function returns false (no-op) instead of throwing.","triggerScenarios":"Calling addRepoToGroup(project, groupPath, registryName) when loadGroupConfig already contains config.repos[groupPath] set to a registry name different from the one passed in.","commonSituations":"Re-registering a repo under a new registry name after it was renamed; two projects in the same group claim the same relative group path; stale group.yaml left behind by a previous run or manual edit.","solutions":["Check the existing mapping with loadGroupConfig and remove or correct config.repos[groupPath] in group.yaml before re-adding.","Pass the same registryName that is already mapped if your intent is a no-op (the function returns false instead of throwing).","Use a different groupPath for the new repo if the old mapping is intentional.","Delete the stale group.yaml (or the single mapping) if the group config is known to be corrupt."],"exampleFix":"// before\nawait addRepoToGroup(project, 'services/api', 'new-registry-name');\n// throws: already mapped to 'old-registry-name'\n\n// after\nconst config = await loadGroupConfig(groupDir);\nif (config.repos['services/api'] !== 'new-registry-name') {\n  delete config.repos['services/api'];\n  await writeGroupConfigAtomic(path.join(groupDir, 'group.yaml'), config);\n}\nawait addRepoToGroup(project, 'services/api', 'new-registry-name');","handlingStrategy":"validation","validationCode":"const config = await loadGroupConfig(groupDir);\nif (config.repos[groupPath] !== undefined && config.repos[groupPath] !== registryName) {\n  throw new Error(`conflict: ${groupPath} mapped to ${config.repos[groupPath]}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await addRepoToGroup(project, groupPath, registryName);\n} catch (err) {\n  if (String(err.message).includes('is already mapped to')) {\n    logger.warn(`group path ${groupPath} already claimed; skipping`);\n    return;\n  }\n  throw err;\n}","preventionTips":["Load and inspect group.yaml before adding mappings.","Treat 'already mapped to same name' (returns false) as success in idempotent retry loops.","Keep group.yaml under source control/review to catch manual edits."],"tags":["config","conflict","auto-sync","state-conflict"],"backgroundTag":"conflicting-config-options","analyzedSha":"0d1aed942f0e8b5d3bac27519fff441aceea722d","analyzedAt":"2026-09-08T00:40:44.970Z","contentChangedAt":"2026-09-08T00:40:44.970Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}