thedotmack/claude-mem · warning

Could not read

Error message

Could not read ${configFile}: ${error instanceof Error ? error.message : String(error)}

What it means

During PATH setup the installer reads the existing shell config file to append an export line. If readFileSync throws, this warning is logged and installation of the PATH entry continues with an empty base (potentially overwriting existing content in the write step). Marked as an accepted anti-pattern because the failure is already surfaced through the interactive-aware log.warn wrapper.

Solutions

  1. Fix read permissions on the config file (chmod u+r).
  2. Check the path is a regular file, not a directory or symlink.
  3. Back up the file before re-running the installer if it contains valuable shell config.
  4. Manually append the export line shown by the installer (`Run manually: echo '...' >> file`).

Example fix

// before
existing = readFileSync(configFile, 'utf-8');
// after
try {
  existing = readFileSync(configFile, 'utf-8');
} catch (e) {
  log.warn(`Could not read ${configFile}; aborting to avoid overwriting config.`);
  log.info(`Run manually: echo '${exportLine}' >> ${configFile}`);
  return;
}
Defensive patterns

Strategy: try-catch

Validate before calling

import { accessSync, constants, statSync } from 'fs';
function isReadableFile(p: string): boolean {
  try { return statSync(p).isFile() && (accessSync(p, constants.R_OK), true); } catch { return false; }
}

Type guard

function isErrnoException(e: unknown): e is NodeJS.ErrnoException {
  return e instanceof Error && typeof (e as NodeJS.ErrnoException).code === 'string';
}

Try / catch

try {
  existing = readFileSync(configFile, 'utf-8');
} catch (error: unknown) {
  log.warn(`Could not read ${configFile}: ${error instanceof Error ? error.message : String(error)}`);
  // prefer aborting over continuing with existing='' to avoid clobbering
}

Prevention

When it happens

Trigger: readFileSync(configFile) throws on a file that existsSync confirmed — race with deletion, permission-denied, or the path being a directory/broken symlink.

Common situations: ~/.zshrc or ~/.bashrc with restrictive permissions; file locked by sync tooling; config replaced by a directory; read-only filesystem (NFS/ro mount).

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17). Data as JSON: /api/errors/0a4926b80d6f7c06. Report an issue: GitHub.

Appendix: source

Thrown at src/npx-cli/commands/install.ts:546

  if (!existsSync(claudeBinary)) return;

  const currentPath = process.env.PATH ?? '';
  const pathEntries = currentPath.split(':');
  if (pathEntries.includes(claudeBinDir)) return;

  const { path: configFile, shell } = detectShellConfigFile();
  const binPathLiteral = '$HOME/.local/bin';
  const exportLine = shell === 'fish'
    ? `set -gx PATH ${claudeBinDir} $PATH`
    : `export PATH="${binPathLiteral}:$PATH"`;

  let existing = '';
  if (existsSync(configFile)) {
    try {
      existing = readFileSync(configFile, 'utf-8');
    } catch (error: unknown) {
      // [ANTI-PATTERN IGNORED]: the failure is already surfaced to the user via the interactive-aware log.warn wrapper below (p.log.warn in a TTY, console.warn otherwise); a raw console call here would double-print.
      log.warn(`Could not read ${configFile}: ${error instanceof Error ? error.message : String(error)}`);
    }
  } else {
    try {
      mkdirSync(dirname(configFile), { recursive: true });
    } catch {
      // Best-effort directory creation.
    }
  }

  if (existing.includes(claudeBinDir) || existing.includes(binPathLiteral)) {
    log.info(`Claude Code PATH already configured in ${configFile}`);
  } else {
    try {
      const trailing = existing.length === 0 || existing.endsWith('\n') ? '' : '\n';
      const block = `${trailing}\n# Added by claude-mem installer for Claude Code\n${exportLine}\n`;
      writeFileSync(configFile, existing + block, 'utf-8');
      log.success(`Added Claude Code to PATH in ${configFile}`);
    } catch (error: unknown) {

View on GitHub (pinned to d8bc9755e7)