affaan-m/ECC · error · Error

Failed to read ${filePath}: ${error.message}

Error message

Failed to read ${filePath}: ${error.message}

What it means

The readJson() function in check-plugin-cache.js wraps JSON.parse(fs.readFileSync(filePath, 'utf8')) in a try-catch and rethrows with the file path and original error message. This error covers both file-not-found (ENOENT) and JSON syntax errors, since both surface as exceptions from the combined read-parse operation.

Source

Thrown at scripts/codex/check-plugin-cache.js:103

  return {
    ...options,
    marketplace: validateCacheSegment('--marketplace', options.marketplace),
    plugin: validateCacheSegment('--plugin', options.plugin),
    version: validateCacheSegment('--version', options.version),
    codexHome: path.resolve(options.codexHome),
    pluginDir: options.pluginDir ? path.resolve(options.pluginDir) : null,
  };
}

function log(message) {
  console.log(`[ecc-codex] ${message}`);
}

function readJson(filePath) {
  try {
    return JSON.parse(fs.readFileSync(filePath, 'utf8'));
  } catch (error) {
    throw new Error(`Failed to read ${filePath}: ${error.message}`);
  }
}

function pluginCacheDir(options) {
  if (options.pluginDir) {
    return options.pluginDir;
  }
  return path.join(
    options.codexHome,
    'plugins',
    'cache',
    options.marketplace,
    options.plugin,
    options.version
  );
}

function listInstalledVersions(options) {

View on GitHub (pinned to 01e15490f0)

Solutions

  1. Check that the plugin cache directory exists: ls ~/.codex/plugins/cache/ecc/ecc/<version>/
  2. If the directory is missing, reinstall the plugin first
  3. If the manifest file exists but is corrupted, remove the cache directory and reinstall
  4. Verify the --version flag matches the actually installed cache version

Example fix

// before — cache not yet populated
node scripts/codex/check-plugin-cache.js
// after — install first, then check
npx ecc-universal install --target codex
node scripts/codex/check-plugin-cache.js
Defensive patterns

Strategy: try-catch

Validate before calling

// Check that the plugin cache directory and manifest exist before running
const fs = require('fs');
const path = require('path');
const os = require('os');
const codexHome = process.env.CODEX_HOME || path.join(os.homedir(), '.codex');
const cacheDir = path.join(codexHome, 'plugins', 'cache', 'ecc', 'ecc', '2.2.0');
const manifestPath = path.join(cacheDir, 'manifest.json');
if (!fs.existsSync(manifestPath)) {
  console.error(`Plugin cache not found at ${manifestPath}`);
  console.error('Install the plugin first: npx ecc-universal install --target codex');
  process.exit(1);
}

Try / catch

// Catch read failures with actionable guidance
try {
  const data = readJson(manifestPath);
} catch (error) {
  if (error.message.startsWith('Failed to read')) {
    console.error('Could not read the plugin cache manifest.');
    console.error(error.message);
    if (error.message.includes('ENOENT')) {
      console.error('The plugin cache does not exist. Run: npx ecc-universal install --target codex');
    } else {
      console.error('The manifest file is corrupted. Remove the cache directory and reinstall.');
    }
    process.exit(1);
  }
  throw error;
}

Prevention

When it happens

Trigger: The Codex plugin cache manifest file does not exist at the expected path (e.g. ~/.codex/plugins/cache/ecc/ecc/2.2.0/manifest.json), the file is unreadable due to permissions, or the file exists but contains invalid JSON. This typically happens when the plugin has not been installed yet, was partially installed, or the cache directory is corrupted.

Common situations: Running check-plugin-cache.js before the plugin has been installed via codex; stale or partially-written cache from an interrupted install; version mismatch between package.json and the cache directory; filesystem permissions preventing read access.

Related errors


AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13). Data as JSON: /api/errors/33c46c6e26003f97. Report an issue: GitHub.