{"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":null,"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  const mergedLabels = { ...DEFAULT_LABELS, ...labels };\n  if (typeof mergedLabels.epic !== 'string' || !mergedLabels.epic.trim()) {\n    throw new Error(`Policy file ${resolvedPath} must define labels.epic as a non-empty string`);\n  }\n  return {\n    ...DEFAULT_POLICY,\n    ...parsed,\n    labels: mergedLabels,","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/github-coordination/policy.js#L48-L84","documentation":"loadPolicy reads a policy JSON file and throws when the file cannot be read or parsed as JSON, wrapping the underlying fs/JSON error with the resolved path. The library requires a readable, valid JSON policy file to configure labels, review, validation, and branch-model behavior, so unreadable or malformed files are a hard failure.","triggerScenarios":"Calling loadPolicy (via policy or result paths) with a path that does not exist, lacks read permission, is a directory, or contains invalid JSON (comments, trailing commas, BOM issues).","commonSituations":"Relative path resolved from the wrong working directory, config file renamed/deleted, team member committing an invalid policy with comments, wrong file extension or path typo in the config flag/env var.","solutions":["Verify the resolved path in the message exists and is a readable file (ls -l <path>).","Run the path through a JSON validator; remove comments/trailing commas — policy files must be strict JSON.","Pass an absolute path or fix the working directory so the relative path resolves correctly.","Restore the policy file from version control if it was deleted or corrupted."],"exampleFix":"// before\nloadPolicy('./policy.jsonc'); // comments not allowed, file missing\n// after\nloadPolicy('/abs/path/to/policy.json'); // strict JSON, absolute path","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction policyFileOk(p) {\n  if (!fs.existsSync(p) || !fs.statSync(p).isFile()) return false;\n  try { JSON.parse(fs.readFileSync(p, 'utf8')); return true; } catch { return false; }\n}\nif (!policyFileOk(policyPath)) throw new Error(`Policy file missing or invalid JSON: ${policyPath}`);","typeGuard":"null","tryCatchPattern":"let policy;\ntry {\n  policy = loadPolicy(path);\n} catch (e) {\n  if (e.message.startsWith('Failed to load policy')) {\n    console.error(`Check that ${path} exists, is readable, and is strict JSON.`, e.message);\n    process.exitCode = 1;\n  } else { throw e; }\n}","preventionTips":["Use absolute paths for policy files.","Commit policy files and CI-check them with a JSON validator.","Never add comments or trailing commas — policy must be strict JSON.","Verify the working directory when using relative paths."],"tags":["config","json","file-read"],"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"}