abhigyanpatwari/GitNexus · warning · Error
Group "${groupName}" already exists. Use --force to overwrit
Error message
Group "${groupName}" already exists. Use --force to overwrite. What it means
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.
Source
Thrown at gitnexus/src/core/group/storage.ts:78
names.push(entry.name);
}
}
}
return names;
} catch (err: unknown) {
if ((err as NodeJS.ErrnoException).code === 'ENOENT') return [];
throw err;
}
}
export async function createGroupDir(
gitnexusDir: string,
groupName: string,
force: boolean = false,
): Promise<string> {
const groupDir = getGroupDir(gitnexusDir, groupName);
if (fs.existsSync(path.join(groupDir, 'group.yaml')) && !force) {
throw new Error(`Group "${groupName}" already exists. Use --force to overwrite.`);
}
await fsp.mkdir(groupDir, { recursive: true });
const template = `version: 1
name: ${groupName}
description: ""
repos: {}
links: []
packages: {}
detect:
http: true
grpc: true
topics: true
shared_libs: trueView on GitHub (pinned to d540b00184)
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.
Example fix
// before — re-create without force throws await createGroupDir(home, 'my-group', false); // after — explicitly opt into overwrite await createGroupDir(home, 'my-group', true); // --force
Defensive patterns
Strategy: validation
Validate before calling
import * as fs from 'node:fs';
function groupAlreadyExists(groupDir: string): boolean {
return fs.existsSync(`${groupDir}/group.yaml`);
}
// decide force before calling createGroupDir:
const force = groupAlreadyExists(groupDir); // or prompt the user Try / catch
import { createGroupDir } from './storage.js';
try {
await createGroupDir(home, name, false);
} catch (err) {
if (err instanceof Error && err.message.includes('already exists')) {
// prompt user, then either pass force=true or pick a new name
return createGroupDir(home, name, true);
}
throw err;
} Prevention
- 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.
When it happens
Trigger: Running a group-create/init command for a group name that already has a group.yaml, without passing --force.
Common situations: 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.
Related errors
- Invalid group name "${name}". Names must start with a letter
- Invalid YAML: expected an object
- version is required in group.yaml
- Unsupported group.yaml version: ${raw.version}. Expected 1.
- name is required in group.yaml
AI-assisted analysis of abhigyanpatwari/GitNexus@d540b00184 (2026-08-12).
Data as JSON: /api/errors/4dbcbbd26353c692.
Report an issue: GitHub.