{"record":{"id":"46a724d9311765b9","repo":"remoteintech/remote-jobs","slug":"could-not-read-file-err-message","errorCode":null,"errorMessage":"Could not read file: ${err.message}","messagePattern":"Could not read file: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":".github/scripts/validate-companies.js","lineNumber":94,"sourceCode":"      currentArrayKey = null;\n    }\n  }\n\n  return data;\n}\n\n/**\n * Validate a single company file. Returns an array of error strings.\n */\nfunction validateCompanyFile(filePath) {\n  const errors = [];\n  const warnings = [];\n  let content;\n\n  try {\n    content = readFileSync(filePath, \"utf-8\");\n  } catch (err) {\n    errors.push(`Could not read file: ${err.message}`);\n    return { errors, warnings };\n  }\n\n  // Parse frontmatter\n  const data = parseFrontmatter(content);\n  if (!data) {\n    errors.push(\n      \"Missing YAML frontmatter. The file must start with `---` followed by YAML fields and a closing `---`.\"\n    );\n    return { errors, warnings };\n  }\n\n  // Check required fields\n  for (const field of REQUIRED_FIELDS) {\n    if (!data[field] || (typeof data[field] === \"string\" && !data[field].trim())) {\n      errors.push(`Missing required field: \\`${field}\\``);\n    }\n  }","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/remoteintech/remote-jobs/blob/b1dd8deb1945e5ff58f9e9c35e318f53c8871930/.github/scripts/validate-companies.js#L76-L112","documentation":"Caught inside validateCompanyFile at lines 91-96. readFileSync(filePath, 'utf-8') is wrapped in try/catch; on any I/O failure (ENOENT, EACCES, EISDIR, ENOTDIR, etc.) the validator pushes `Could not read file: <err.message>` and returns early. The script still exits 1 because results.summary.failed becomes > 0.","triggerScenarios":"The changed-files argument list names a path that doesn't exist on disk (ENOENT); the pr-head/ prefix from a pull_request_target checkout wasn't stripped correctly (line 220) leaving an unresolvable path; the file was deleted in the PR but still listed; CI runner lacks read permission (EACCES); the path is actually a directory (EISDIR).","commonSituations":"Renaming a company file but the workflow still references the old path; checkout action didn't fetch the file at the expected location; case-sensitive filesystem mismatch (macOS dev vs Linux CI); a glob included a path that was removed in a force-push.","solutions":["Run `ls -l <printed path>` to confirm existence and permissions.","If running under pull_request_target, verify the pr-head/ stripping at line 220 produced a real filesystem path.","Regenerate the changed-files list from git diff rather than a stale matrix.","Match the path casing exactly to what git tracks."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import { existsSync, readFileSync } from 'node:fs';\nfunction readCompany(filePath) {\n  if (!existsSync(filePath)) {\n    return { errors: [`File not found: ${filePath}`], warnings: [] };\n  }\n  return readFileSync(filePath, 'utf-8');\n}","typeGuard":null,"tryCatchPattern":"try {\n  content = readFileSync(filePath, 'utf-8');\n} catch (err) {\n  errors.push(`Could not read file: ${err.message}`);\n  return { errors, warnings };\n}","preventionTips":["Filter the changed-files list through existsSync before invoking the validator.","Surface err.code (ENOENT/EACCES/EISDIR) alongside err.message for faster diagnosis.","Verify the pr-head/ stripping logic at line 220 matches the actual checkout layout."],"tags":["filesystem","enoent","ci","readfile"],"backgroundTag":null,"analyzedSha":"b1dd8deb1945e5ff58f9e9c35e318f53c8871930","analyzedAt":"2026-08-13T04:09:00.804Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}