{"record":{"id":"262c7447c3fdf5d6","repo":"affaan-m/ECC","slug":"failed-to-parse-label-error-message","errorCode":null,"errorMessage":"Failed to parse ${label}: ${error.message}","messagePattern":"Failed to parse (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/lib/install/claude-settings.js","lineNumber":315,"sourceCode":"function materializeManagedHooks(hooksConfig, targetRoot) {\n  if (!isJsonObject(hooksConfig) || !isJsonObject(hooksConfig.hooks)) {\n    throw new Error('Invalid hooks config: expected a JSON object with a hooks object');\n  }\n  if (!isNonEmptyString(targetRoot)) {\n    throw new Error('Invalid Claude target root: expected a non-empty string');\n  }\n  return validateManagedHooks(resolveManagedHookCommands(\n    replacePluginRootPlaceholders(hooksConfig.hooks, targetRoot),\n    targetRoot\n  ));\n}\n\nfunction parseSettings(rawSettings, label = 'Claude settings') {\n  let settings;\n  try {\n    settings = JSON.parse(rawSettings);\n  } catch (error) {\n    throw new Error(`Failed to parse ${label}: ${error.message}`, { cause: error });\n  }\n  return validateSettings(settings, label);\n}\n\nfunction readSettings(settingsPath, fileSystem = fs) {\n  const reader = fileSystem && fileSystem.fs ? fileSystem.fs : fileSystem;\n  let rawSettings;\n  try {\n    rawSettings = reader.readFileSync(settingsPath, 'utf8');\n  } catch (error) {\n    if (error && error.code === 'ENOENT') {\n      return {};\n    }\n    throw error;\n  }\n  return parseSettings(rawSettings, `Claude settings at ${settingsPath}`);\n}\n","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/install/claude-settings.js#L297-L333","documentation":"parseSettings wraps JSON.parse of raw Claude settings text and rethrows any SyntaxError with a labeled message identifying which settings file failed to parse. The original parse error is preserved as the `cause` for diagnostics. This guards callers (readSettings, readSettingsSnapshot, runTests) from opaque JSON syntax errors with no file context.","triggerScenarios":"Calling readSettings(path) or readSettingsSnapshot(path) when the file at settingsPath contains malformed JSON (trailing commas, truncated file, BOM, comments in JSONC format), or passing a non-JSON string directly to parseSettings.","commonSituations":"A user hand-edited ~/.claude/settings.json and left a trailing comma or comment; an interrupted write left the file truncated; the settings file was saved as JSONC by an editor expecting comments.","solutions":["Open the settings file and fix the JSON syntax; the `cause` property and error message list the exact parse position.","Validate the file with `node -e \"JSON.parse(require('fs').readFileSync(process.argv[1],'utf8'))\" <path>` before rerunning.","If hand-edits keep breaking, restore the file from version control or let the installer regenerate it.","If the file is JSONC (with comments), strip comments before storing as settings.json."],"exampleFix":"// before (settings.json)\n{\n  \"hooks\": {...},\n}\n// after (remove trailing comma)\n{\n  \"hooks\": {...}\n}","handlingStrategy":"try-catch","validationCode":"const raw = fs.readFileSync(settingsPath, 'utf8').replace(/^\\uFEFF/, '');\ntry { JSON.parse(raw); } catch (e) { throw new Error(`${settingsPath} is not valid JSON: ${e.message}`); }","typeGuard":"function isParseableJson(text) { try { JSON.parse(text); return true; } catch { return false; } }","tryCatchPattern":"try {\n  const settings = readSettings(path);\n} catch (error) {\n  if (error.message.startsWith('Failed to parse')) {\n    console.error(`Fix JSON in ${path}:`, error.cause?.message);\n    return;\n  }\n  throw error;\n}","preventionTips":["Never hand-edit settings.json without validating JSON afterward","Use a JSON linter/formatter on ~/.claude files","Keep settings files in git so corruption is recoverable","Avoid JSONC features (comments, trailing commas) in settings files"],"tags":["json","settings","parse-error","config"],"backgroundTag":"json-parse-error","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"}