abhigyanpatwari/GitNexus · error · GitNexusRcError

Could not read ${GITNEXUS_RC_FILENAME}: ${(err as Error).mes

Error message

Could not read ${GITNEXUS_RC_FILENAME}: ${(err as Error).message}

What it means

`.gitnexusrc` exists at the resolved repo root but `fs.readFileSync` failed for a reason other than ENOENT (file-not-found returns `undefined` silently, the normal no-config case). Typical causes are EACCES (permission denied), a broken symlink, or an I/O error on the mount. The original error message is appended.

Source

Thrown at gitnexus/src/cli/analyze-config.ts:379

  return out;
};

/**
 * Locate, read, parse, validate, and normalize `.gitnexusrc` at `repoRoot`.
 *
 * @returns the normalized config defaults, or `undefined` when no file exists
 *          (the normal case). Throws {@link GitNexusRcError} on any problem.
 */
export function loadAnalyzeConfig(repoRoot: string): Partial<AnalyzeOptions> | undefined {
  const filePath = path.join(repoRoot, GITNEXUS_RC_FILENAME);

  let raw: string;
  try {
    raw = fs.readFileSync(filePath, 'utf-8');
  } catch (err) {
    if ((err as NodeJS.ErrnoException)?.code === 'ENOENT') return undefined;
    throw new GitNexusRcError(`Could not read ${GITNEXUS_RC_FILENAME}: ${(err as Error).message}`);
  }

  // Strip a leading UTF-8 BOM: Node's 'utf-8' decode keeps it, and JSON.parse
  // then fails with a confusing "Unexpected token" on an otherwise-valid file
  // (#1996 tri-review). Only one leading BOM is stripped; in-string control
  // rejection still applies to the parsed values.
  if (raw.charCodeAt(0) === 0xfeff) raw = raw.slice(1);

  let parsed: unknown;
  try {
    parsed = JSON.parse(raw);
  } catch (err) {
    throw new GitNexusRcError(
      `${GITNEXUS_RC_FILENAME} is not valid JSON: ${(err as Error).message}. ` +
        `Expected a JSON object such as {"defaultBranch": "develop", "skipContextFiles": true}.`,
    );
  }

View on GitHub (pinned to d540b00184)

Solutions

  1. Check permissions and ownership: `ls -la .gitnexusrc` and ensure the running user can read it.
  2. If it is a broken symlink, remove it: `rm .gitnexusrc` and recreate as a real file.
  3. If unintended, delete the file so the normal no-config path applies.
  4. On Docker/CI, set the file mode to 0644 or chown it to the container user.

Example fix

# before (EACCES on mode 0600 owned by root)
# after
chmod 644 .gitnexusrc
Defensive patterns

Strategy: try-catch

Validate before calling

import fs from 'node:fs';
try {
  fs.accessSync('.gitnexusrc', fs.constants.R_OK);
} catch (e) {
  console.error('.gitnexusrc is not readable by this user');
}

Try / catch

try {
  const cfg = loadAnalyzeConfig(repoRoot);
} catch (e) {
  if (e instanceof GitNexusRcError && e.message.startsWith('Could not read')) {
    cliError(e.message + ' — verify file permissions and ownership.');
    process.exit(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: File mode 0000 or owned by another user (EACCES); `.gitnexusrc` is a dangling symlink; the repo root is on a read-only or failing mount.

Common situations: CI/Docker running as a different UID than the file owner; restricted bind-mounts; NFS permissions; a teammate committed a symlink by mistake.

Related errors


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