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: true

View on GitHub (pinned to d540b00184)

Solutions

  1. If you intended to reset the group, pass --force (force=true) — it will overwrite group.yaml with the template.
  2. If you intended to edit the existing group, do not re-create it; instead load and modify the existing group.yaml.
  3. 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

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


AI-assisted analysis of abhigyanpatwari/GitNexus@d540b00184 (2026-08-12). Data as JSON: /api/errors/4dbcbbd26353c692. Report an issue: GitHub.