abhigyanpatwari/GitNexus · error · Error

Unable to read eval-server authentication from ${filePath}

Error message

Unable to read eval-server authentication from ${filePath}

What it means

The eval-server attempted to read `.env` / `.env.local` for `GITNEXUS_AUTH_TOKEN` and Node's `parseEnv` threw (ENOENT — file missing — is handled and returns undefined). This means the env file exists but is malformed: `parseEnv` rejects invalid KEY=value lines. The original error is attached via `Error.cause`.

Source

Thrown at gitnexus/src/cli/eval-server.ts:107

): Promise<string | null> {
  const directHost = validateHost(raw);
  if (directHost && directHost !== 'localhost') return directHost;
  if (directHost !== 'localhost' && !isHostname(raw)) return null;

  try {
    const address = await resolveHostname(raw);
    return isIPv4(address) ? address : null;
  } catch {
    return null;
  }
}

function readAuthTokenFile(filePath: string): string | undefined {
  try {
    return parseEnv(readFileSync(filePath, 'utf8')).GITNEXUS_AUTH_TOKEN?.trim() || undefined;
  } catch (error) {
    if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined;
    throw new Error(`Unable to read eval-server authentication from ${filePath}`, { cause: error });
  }
}

/** Resolve the bearer token from the shell, then .env.local, then .env. */
export function resolveEvalServerAuthToken(
  env: NodeJS.ProcessEnv,
  cwd: string = process.cwd(),
): string | undefined {
  if (Object.hasOwn(env, 'GITNEXUS_AUTH_TOKEN')) {
    return env.GITNEXUS_AUTH_TOKEN?.trim() || undefined;
  }

  return (
    readAuthTokenFile(path.join(cwd, '.env.local')) ?? readAuthTokenFile(path.join(cwd, '.env'))
  );
}

/** True only for literal loopback addresses; DNS names are resolved before this check. */

View on GitHub (pinned to d540b00184)

Solutions

  1. Inspect `.env` and `.env.local` for malformed lines and fix them to KEY=value.
  2. Quote values containing special characters or #.
  3. Set GITNEXUS_AUTH_TOKEN in the shell environment instead of the file to bypass parsing.
  4. If the file is unused, remove it so the ENOENT path applies.

Example fix

# before
GITNEXUS_AUTH_TOKEN=abc # comment with space
# after
GITNEXUS_AUTH_TOKEN="abc"
Defensive patterns

Strategy: try-catch

Validate before calling

import { parseEnv } from 'node:util';
import { readFileSync } from 'node:fs';
// Pre-flight: ensure the env file parses before starting the server
for (const f of ['.env.local', '.env']) {
  try {
    parseEnv(readFileSync(f, 'utf8'));
  } catch (e) {
    console.error(f + ' is malformed:', e.message);
  }
}

Try / catch

try {
  resolveEvalServerAuthTokenForHost(host, process.env);
} catch (e) {
  if (isEvalServerLoopbackHost(host)) {
    cliWarn(e.message + ' Continuing without auth on loopback.');
  } else {
    throw e; // non-loopback: surface the failure
  }
}

Prevention

When it happens

Trigger: An `.env` line with an invalid KEY=value shape that `node:util.parseEnv` rejects, e.g. a line without `=`, or reserved/unescapeable sequences.

Common situations: Manually authored `.env` with unusual formatting; a line copied from a shell script with `export` prefixes or inline comments; merge conflicts leaving garbage in the file.

Understand the failure class

Related errors


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