{"record":{"id":"953cb80de2c18c96","repo":"affaan-m/ECC","slug":"invalid-label-error-message","errorCode":null,"errorMessage":"Invalid ${label}: ${error.message}","messagePattern":"Invalid (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/lib/install-lifecycle.js","lineNumber":268,"sourceCode":"\nfunction cloneJsonValue(value) {\n  if (value === undefined) {\n    return undefined;\n  }\n\n  return JSON.parse(JSON.stringify(value));\n}\n\nfunction parseJsonLikeValue(value, label) {\n  if (value === undefined) {\n    return undefined;\n  }\n\n  if (typeof value === 'string') {\n    try {\n      return JSON.parse(value);\n    } catch (error) {\n      throw new Error(`Invalid ${label}: ${error.message}`);\n    }\n  }\n\n  if (value === null || Array.isArray(value) || isPlainObject(value) || typeof value === 'number' || typeof value === 'boolean') {\n    return cloneJsonValue(value);\n  }\n\n  throw new Error(`Invalid ${label}: expected JSON-compatible data`);\n}\n\nfunction getOperationTextContent(operation) {\n  const candidateKeys = ['renderedContent', 'content', 'managedContent', 'expectedContent', 'templateOutput'];\n\n  for (const key of candidateKeys) {\n    if (typeof operation[key] === 'string') {\n      return operation[key];\n    }\n  }","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/install-lifecycle.js#L250-L286","documentation":"parseJsonLikeValue accepts either an already-JSON value or a string it tries to JSON.parse. When a string payload (e.g. operation.mergePayload / payload / previousValue for update-claude-settings operations) is not valid JSON, the original JSON.parse SyntaxError message is wrapped as `Invalid <kind>.<key>: <message>`. The label identifies which operation field failed so the broken state record can be located.","triggerScenarios":"getOperationJsonPayload or getOperationPreviousJson reads a string-typed value from operation fields mergePayload/managedPayload/payload/value/expectedValue or previousValue/previousJson/originalValue, and JSON.parse fails on it — e.g. trailing commas, single quotes, comments, truncated JSON, or JS object-literal syntax stored as a string.","commonSituations":"Hand-editing install-state JSON payloads and leaving a trailing comma or unquoted key; a template or script serializing settings with JSON5-ish syntax; truncation of a long settings payload; paste of a JS object literal into a JSON string field.","solutions":["Fix the string payload named by the error label (e.g. 'update-claude-settings.mergePayload') so it is valid JSON — validate with JSON.parse in isolation or a linter.","If the value can be an object instead of a string, store it as a native JSON object/array rather than a serialized string.","Regenerate the install state (re-run install) instead of hand-repairing the payload string.","If the input may be JSON5 or comments, normalize it to strict JSON before handing it to the lifecycle functions."],"exampleFix":"// before (state file)\n\"mergePayload\": \"{ 'hooks': { 'SessionStart': [] }, }\"\n\n// after\n\"mergePayload\": \"{\\\"hooks\\\":{\\\"SessionStart\\\":[]}}\"","handlingStrategy":"validation","validationCode":"function assertValidJsonString(value, label) {\n  if (typeof value === 'string') JSON.parse(value); // throws early with a clear location\n}","typeGuard":"function isJsonString(value) {\n  if (typeof value !== 'string') return false;\n  try { JSON.parse(value); return true; } catch { return false; }\n}","tryCatchPattern":"try {\n  await applyOperation(op);\n} catch (err) {\n  const m = /^Invalid ([\\w.-]+): /.exec(err.message);\n  if (m) {\n    console.error(`Field ${m[1]} is not valid JSON; fix the state record and re-run.`);\n  } else throw err;\n}","preventionTips":["Store payloads as native JSON values instead of serialized strings whenever possible.","Validate JSON strings with a linter/formatter before writing them into install-state.","Never paste JS object literals (single quotes, trailing commas, comments) into JSON fields."],"tags":["json","parse","state"],"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"}