{"record":{"id":"3090575c2e216dee","repo":"affaan-m/ECC","slug":"failed-to-read-path-basename-filepath-error-message","errorCode":null,"errorMessage":"Failed to read ${path.basename(filePath)}: ${error.message}","messagePattern":"Failed to read (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/ci/catalog.js","lineNumber":68,"sourceCode":"function buildCatalog(root = ROOT) {\n  const agents = listMatchingFiles(root, 'agents', entry => entry.isFile() && entry.name.endsWith('.md'));\n  const commands = listMatchingFiles(root, 'commands', entry => entry.isFile() && entry.name.endsWith('.md'));\n  const skills = listMatchingFiles(root, 'skills', entry => (\n    entry.isDirectory() && fs.existsSync(path.join(root, 'skills', entry.name, 'SKILL.md'))\n  )).map(skillDir => `${skillDir}/SKILL.md`);\n\n  return {\n    agents: { count: agents.length, files: agents, glob: 'agents/*.md' },\n    commands: { count: commands.length, files: commands, glob: 'commands/*.md' },\n    skills: { count: skills.length, files: skills, glob: 'skills/*/SKILL.md' }\n  };\n}\n\nfunction readFileOrThrow(filePath) {\n  try {\n    return fs.readFileSync(filePath, 'utf8');\n  } catch (error) {\n    throw new Error(`Failed to read ${path.basename(filePath)}: ${error.message}`);\n  }\n}\n\nfunction writeFileOrThrow(filePath, content) {\n  try {\n    fs.writeFileSync(filePath, content, 'utf8');\n  } catch (error) {\n    throw new Error(`Failed to write ${path.basename(filePath)}: ${error.message}`);\n  }\n}\n\nfunction replaceOrThrow(content, regex, replacer, source) {\n  if (!regex.test(content)) {\n    throw new Error(`${source} is missing the expected catalog marker`);\n  }\n\n  return content.replace(regex, replacer);\n}","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/ci/catalog.js#L50-L86","documentation":"readFileOrThrow in scripts/ci/catalog.js wraps fs.readFileSync and converts ENOENT/EACCES/etc. failures into a uniform Error prefixed with the file's basename and the original Node error message. Catalog sync/check routines rely on tracked files existing and being readable.","triggerScenarios":"Calling any routine that reads a tracked catalog file (e.g. install manifests, command registry) when the file does not exist at the expected repo-relative path, or lacks read permission.","commonSituations":"Running the CI catalog check in a partial checkout or wrong working directory; a newly added component whose manifest file was never created; a file renamed during refactor while CI still expects the old path; permission issues on shared runners.","solutions":["Check the file exists at the path named in the message and create/restore it if missing","Run the script from the repository root so relative paths resolve","Restore the file with git (`git checkout -- <path>`) if it was deleted or renamed","Fix filesystem permissions if the message shows EACCES"],"exampleFix":"// before (file missing)\nError: Failed to read install-components.json: ENOENT...\n// after\ngit checkout -- manifests/install-components.json\nnode scripts/ci/catalog.js check","handlingStrategy":"try-catch","validationCode":"const fs = require('fs');\nif (!fs.existsSync(filePath)) {\n  console.error(`Expected file missing: ${filePath} — restore it or run from repo root`);\n  process.exit(1);\n}","typeGuard":"function isReadableFile(p) {\n  try { return fs.statSync(p).isFile() && fs.accessSync(p, fs.constants.R_OK) === undefined; } catch { return false; }\n}","tryCatchPattern":"try {\n  const content = readFileOrThrow(filePath);\n} catch (err) {\n  if (/^Failed to read/.test(err.message)) {\n    console.error(`Cannot read ${filePath}: ${err.message}. Run from repo root and verify the file exists.`);\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Run CI catalog scripts from the repository root","Commit all manifest files the checker expects","Restore renamed/deleted files before running checks","Verify file permissions on shared runners"],"tags":["filesystem","file-read","ci"],"backgroundTag":"file-read-failed","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}