{"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":"Error","httpStatus":null,"severity":"warning","filePath":"gitnexus/src/core/group/storage.ts","lineNumber":78,"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  grpc: true\n  topics: true\n  shared_libs: true","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/gitnexus/src/core/group/storage.ts#L60-L96","documentation":"Thrown by createGroupDir when a group.yaml already exists at the target directory and the force flag is false. This protects an existing group from being silently overwritten by a fresh template. Passing force=true unlinks the existing file (best-effort) before writing with O_EXCL.","triggerScenarios":"Running a group-create/init command for a group name that already has a group.yaml, without passing --force.","commonSituations":"Re-running a setup script that invokes group create; a CI pipeline creating a group each run without --force; accidentally re-initializing a group you intended to edit instead.","solutions":["If you intended to reset the group, pass --force (force=true) — it will overwrite group.yaml with the template.","If you intended to edit the existing group, do not re-create it; instead load and modify the existing group.yaml.","Pick a different group name for the new group."],"exampleFix":"// before — re-create without force throws\nawait createGroupDir(home, 'my-group', false);\n\n// after — explicitly opt into overwrite\nawait createGroupDir(home, 'my-group', true); // --force","handlingStrategy":"validation","validationCode":"import * as fs from 'node:fs';\nfunction groupAlreadyExists(groupDir: string): boolean {\n  return fs.existsSync(`${groupDir}/group.yaml`);\n}\n// decide force before calling createGroupDir:\nconst force = groupAlreadyExists(groupDir); // or prompt the user","typeGuard":null,"tryCatchPattern":"import { createGroupDir } from './storage.js';\ntry {\n  await createGroupDir(home, name, false);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('already exists')) {\n    // prompt user, then either pass force=true or pick a new name\n    return createGroupDir(home, name, true);\n  }\n  throw err;\n}","preventionTips":["Check groupAlreadyExists before calling createGroupDir to choose force intentionally.","Make group creation idempotent in CI by either passing --force or guarding with a list check first.","Don't use group-create to edit — load and modify the existing manifest instead."],"tags":["group-config","exists","create","storage","recoverable"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}