{"record":{"id":"8e8b99756ed45d84","repo":"affaan-m/ECC","slug":"failed-to-load-policy-from-resolvedpath-erro","errorCode":null,"errorMessage":"Failed to load policy from ${resolvedPath}: ${error.message}","messagePattern":"Failed to load policy from (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/github-coordination/policy.js","lineNumber":66,"sourceCode":"});\n\nfunction loadPolicy(rootDir = process.cwd(), configPath = null) {\n  const resolvedPath = configPath\n    ? path.resolve(configPath)\n    : path.join(rootDir, 'config', DEFAULT_CONFIG_FILE);\n\n  if (!fs.existsSync(resolvedPath)) {\n    return {\n      ...DEFAULT_POLICY,\n      sourcePath: null,\n    };\n  }\n\n  let parsed;\n  try {\n    parsed = JSON.parse(fs.readFileSync(resolvedPath, 'utf8'));\n  } catch (error) {\n    throw new Error(`Failed to load policy from ${resolvedPath}: ${error.message}`);\n  }\n  if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {\n    throw new Error(`Policy file ${resolvedPath} must contain a JSON object, got ${Array.isArray(parsed) ? 'array' : typeof parsed}`);\n  }\n  const labels = typeof parsed.labels === 'object' && parsed.labels !== null && !Array.isArray(parsed.labels) ? parsed.labels : {};\n  const review = typeof parsed.review === 'object' && parsed.review !== null && !Array.isArray(parsed.review) ? parsed.review : {};\n  const validation = typeof parsed.validation === 'object' && parsed.validation !== null && !Array.isArray(parsed.validation) ? parsed.validation : {};\n  const branchModel = typeof parsed.branchModel === 'object' && parsed.branchModel !== null && !Array.isArray(parsed.branchModel) ? parsed.branchModel : {};\n  const project = typeof parsed.project === 'object' && parsed.project !== null && !Array.isArray(parsed.project) ? parsed.project : {};\n  const fieldNames = typeof project.fieldNames === 'object' && project.fieldNames !== null && !Array.isArray(project.fieldNames) ? project.fieldNames : {};\n  return {\n    ...DEFAULT_POLICY,\n    ...parsed,\n    labels: { ...DEFAULT_LABELS, ...labels },\n    review: { ...DEFAULT_POLICY.review, ...review },\n    validation: { ...DEFAULT_POLICY.validation, ...validation },\n    branchModel: { ...DEFAULT_POLICY.branchModel, ...branchModel },\n    project: {","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/lib/github-coordination/policy.js#L48-L84","documentation":"Thrown by loadPolicy() in scripts/lib/github-coordination/policy.js when the coordination policy file exists at the resolved path but cannot be read or parsed as JSON. The error wraps the underlying readFileSync/JSON.parse failure so the caller knows which file broke and why.","triggerScenarios":"loadPolicy(rootDir, configPath) is called, fs.existsSync(resolvedPath) returns true, then either fs.readFileSync throws (permissions, EISDIR, EACCES) or JSON.parse throws (trailing comma, unquoted keys, BOM, truncated file).","commonSituations":"Hand-edited config/github-native-coordination.json with a syntax error; file saved with a leading BOM or CRLF inside a string; file replaced by a directory or symlink to a missing target; permissions locked down so Node cannot read it.","solutions":["Validate the file with a JSON linter: node -e \"JSON.parse(require('fs').readFileSync('config/github-native-coordination.json','utf8'))\" and fix the reported syntax error.","Confirm the path is a regular file: ls -l <resolvedPath> and ensure it is not a directory or broken symlink.","Check read permissions: chmod +r <resolvedPath> or run the command as a user with access.","If you do not need a custom policy, delete or rename the file; loadPolicy returns DEFAULT_POLICY when the file is absent."],"exampleFix":"// before: config/github-native-coordination.json contains { labels: { epic: \"epic\" } } (unquoted-ish / trailing comma)\n// after:\n{\n  \"labels\": { \"epic\": \"epic\" }\n}","handlingStrategy":"try-catch","validationCode":"const fs = require('fs');\nfunction canLoadPolicy(p) {\n  if (!fs.existsSync(p)) return true; // absent is OK\n  try { JSON.parse(fs.readFileSync(p, 'utf8')); return true; }\n  catch { return false; }\n}\nif (!canLoadPolicy(resolvedPath)) {\n  console.error(`${resolvedPath} is not valid JSON; using defaults`);\n}","typeGuard":null,"tryCatchPattern":"let policy;\ntry {\n  policy = loadPolicy(rootDir, configPath);\n} catch (err) {\n  if (/Failed to load policy/.test(err.message)) {\n    console.warn(`${err.message} — falling back to DEFAULT_POLICY`);\n    policy = require('./policy').DEFAULT_POLICY;\n  } else {\n    throw err;\n  }\n}","preventionTips":["Lint the policy file in pre-commit hooks using a JSON validator.","Treat config/github-native-coordination.json as code: review diffs before merge.","Document the schema (e.g. with a JSON Schema file) and validate on save.","Run the ECC test suite after editing the policy file."],"tags":["config","json","parsing","github-coordination"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}