{"record":{"id":"33c46c6e26003f97","repo":"affaan-m/ECC","slug":"failed-to-read-filepath-error-message","errorCode":null,"errorMessage":"Failed to read ${filePath}: ${error.message}","messagePattern":"Failed to read (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/codex/check-plugin-cache.js","lineNumber":103,"sourceCode":"  return {\n    ...options,\n    marketplace: validateCacheSegment('--marketplace', options.marketplace),\n    plugin: validateCacheSegment('--plugin', options.plugin),\n    version: validateCacheSegment('--version', options.version),\n    codexHome: path.resolve(options.codexHome),\n    pluginDir: options.pluginDir ? path.resolve(options.pluginDir) : null,\n  };\n}\n\nfunction log(message) {\n  console.log(`[ecc-codex] ${message}`);\n}\n\nfunction readJson(filePath) {\n  try {\n    return JSON.parse(fs.readFileSync(filePath, 'utf8'));\n  } catch (error) {\n    throw new Error(`Failed to read ${filePath}: ${error.message}`);\n  }\n}\n\nfunction pluginCacheDir(options) {\n  if (options.pluginDir) {\n    return options.pluginDir;\n  }\n  return path.join(\n    options.codexHome,\n    'plugins',\n    'cache',\n    options.marketplace,\n    options.plugin,\n    options.version\n  );\n}\n\nfunction listInstalledVersions(options) {","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/codex/check-plugin-cache.js#L85-L121","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check that the plugin cache directory exists: ls ~/.codex/plugins/cache/ecc/ecc/<version>/","If the directory is missing, reinstall the plugin first","If the manifest file exists but is corrupted, remove the cache directory and reinstall","Verify the --version flag matches the actually installed cache version"],"exampleFix":"// before — cache not yet populated\nnode scripts/codex/check-plugin-cache.js\n// after — install first, then check\nnpx ecc-universal install --target codex\nnode scripts/codex/check-plugin-cache.js","handlingStrategy":"try-catch","validationCode":"// Check that the plugin cache directory and manifest exist before running\nconst fs = require('fs');\nconst path = require('path');\nconst os = require('os');\nconst codexHome = process.env.CODEX_HOME || path.join(os.homedir(), '.codex');\nconst cacheDir = path.join(codexHome, 'plugins', 'cache', 'ecc', 'ecc', '2.2.0');\nconst manifestPath = path.join(cacheDir, 'manifest.json');\nif (!fs.existsSync(manifestPath)) {\n  console.error(`Plugin cache not found at ${manifestPath}`);\n  console.error('Install the plugin first: npx ecc-universal install --target codex');\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"// Catch read failures with actionable guidance\ntry {\n  const data = readJson(manifestPath);\n} catch (error) {\n  if (error.message.startsWith('Failed to read')) {\n    console.error('Could not read the plugin cache manifest.');\n    console.error(error.message);\n    if (error.message.includes('ENOENT')) {\n      console.error('The plugin cache does not exist. Run: npx ecc-universal install --target codex');\n    } else {\n      console.error('The manifest file is corrupted. Remove the cache directory and reinstall.');\n    }\n    process.exit(1);\n  }\n  throw error;\n}","preventionTips":["Always install the Codex plugin before running the cache checker","If the cache is corrupted, remove ~/.codex/plugins/cache/ecc/ and reinstall","Verify the --version flag matches the installed cache version","In CI, run install before check-plugin-cache in the same job"],"tags":["json","file-io","codex","plugin-cache"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}