{"record":{"id":"4dbcbbd26353c692","repo":"abhigyanpatwari/GitNexus","slug":"group-groupname-already-exists-use-force-t","errorCode":null,"errorMessage":"Group \"${groupName}\" already exists. Use --force to overwrite.","messagePattern":"Group \"(.+?)\" already exists\\. Use --force to overwrite\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/group/storage.ts","lineNumber":83,"sourceCode":"          names.push(entry.name);\n        }\n      }\n    }\n    return names;\n  } catch (err: unknown) {\n    if ((err as NodeJS.ErrnoException).code === 'ENOENT') return [];\n    throw err;\n  }\n}\n\nexport async function createGroupDir(\n  gitnexusDir: string,\n  groupName: string,\n  force: boolean = false,\n): Promise<string> {\n  const groupDir = getGroupDir(gitnexusDir, groupName);\n  if (fs.existsSync(path.join(groupDir, 'group.yaml')) && !force) {\n    throw new Error(`Group \"${groupName}\" already exists. Use --force to overwrite.`);\n  }\n  await fsp.mkdir(groupDir, { recursive: true });\n\n  const template = `version: 1\nname: ${groupName}\ndescription: \"\"\n\nrepos: {}\n\nlinks: []\n\npackages: {}\n\ndetect:\n  http: true\n  graphql: false\n  grpc: true\n  topics: true","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/0d1aed942f0e8b5d3bac27519fff441aceea722d/gitnexus/src/core/group/storage.ts#L65-L101","documentation":"Thrown by createGroupDir() in gitnexus/src/core/group/storage.ts when the target group directory already contains a group.yaml (the marker of an initialized group) and force is false. It protects an existing group's config and member repos from being silently overwritten by the YAML template.","triggerScenarios":"Running the group-create command twice with the same groupName without --force, e.g. re-running `gitnexus group create my-group` after the first invocation already wrote groups/my-group/group.yaml.","commonSituations":"Idempotent bootstrap or provisioning scripts that create groups on every run; CI pipelines that re-execute a setup step; retrying a command that actually succeeded the first time.","solutions":["Pass --force (force=true in createGroupDir) when you intentionally want to overwrite the existing group","Make the setup script idempotent: check whether <gitnexusDir>/groups/<name>/group.yaml exists before creating","Use a different group name if this is meant to be a new, separate group"],"exampleFix":"// before\nawait createGroupDir(gitnexusDir, 'my-group'); // throws if group.yaml exists\n// after\nawait createGroupDir(gitnexusDir, 'my-group', /* force */ true);","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nimport path from 'node:path';\n\nconst groupYaml = path.join(gitnexusDir, 'groups', groupName, 'group.yaml');\nif (fs.existsSync(groupYaml)) {\n  if (!shouldOverwrite) {\n    console.log(`Group ${groupName} already exists — skipping (idempotent).`);\n    process.exit(0);\n  }\n}\nawait createGroupDir(gitnexusDir, groupName, shouldOverwrite);","typeGuard":null,"tryCatchPattern":"try {\n  await createGroupDir(gitnexusDir, groupName, force);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('already exists')) {\n    // decide: skip, pick a new name, or re-call with force=true\n  }\n  throw err;\n}","preventionTips":["Make provisioning scripts idempotent: probe for groups/<name>/group.yaml before creating","Treat 'already exists' as a success signal in setup automation, not a failure","Only pass --force when you intend to discard the group's current config and members"],"tags":["groups","idempotency","cli","overwrite-protection"],"backgroundTag":"resource-already-exists","analyzedSha":"0d1aed942f0e8b5d3bac27519fff441aceea722d","analyzedAt":"2026-08-20T23:29:22.980Z","contentChangedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}