{"record":{"id":"953cb80de2c18c96","repo":"affaan-m/ECC","slug":"invalid-label-error-message","errorCode":null,"errorMessage":"Invalid ${label}: ${error.message}","messagePattern":"Invalid (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/install-lifecycle.js","lineNumber":162,"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":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/lib/install-lifecycle.js#L144-L180","documentation":"Thrown by parseJsonLikeValue() in scripts/lib/install-lifecycle.js when the input value is a string that fails JSON.parse. The label identifies the operation field that held the bad string (e.g. 'merge-json.mergePayload').","triggerScenarios":"parseJsonLikeValue(value, label) where typeof value === 'string' but JSON.parse throws. Called from getOperationJsonPayload / getOperationPreviousJson for fields like mergePayload, managedPayload, payload, value, previousValue, etc.","commonSituations":"Install operation carries a JSON payload as a malformed string (trailing comma, unquoted key, single quotes); template renderer emitted JS object literal syntax instead of JSON; user-supplied --set value was not valid JSON.","solutions":["Inspect the operation field named in the label; reproduce the JSON.parse in isolation.","Switch single quotes to double quotes; remove trailing commas; quote object keys.","If the field is meant to hold free text, change the operation to pass an already-parsed object, not a JSON string.","Validate user input with a JSON schema before constructing the operation."],"exampleFix":"// before\noperation.mergePayload = \"{ key: 'value' }\"; // not JSON\n\n// after\noperation.mergePayload = JSON.stringify({ key: 'value' });\n// or pass the object directly\noperation.mergePayload = { key: 'value' };","handlingStrategy":"try-catch","validationCode":"function isJsonString(s) {\n  if (typeof s !== 'string') return false;\n  try { JSON.parse(s); return true; } catch { return false; }\n}\nif (typeof value === 'string' && !isJsonString(value)) {\n  throw new Error(`${label} is not valid JSON: ${value.slice(0, 120)}`);\n}","typeGuard":"function isParsableJson(s) {\n  if (typeof s !== 'string') return false;\n  try { JSON.parse(s); return true; } catch { return false; }\n}","tryCatchPattern":"try {\n  return parseJsonLikeValue(value, label);\n} catch (err) {\n  if (/Invalid .*:/.test(err.message) && typeof value === 'string') {\n    throw new Error(`${label} must be valid JSON. Got: ${value.slice(0, 120)}`);\n  }\n  throw err;\n}","preventionTips":["Pass structured payloads as objects, not JSON strings, when possible.","Validate user-provided --set values with JSON.parse before constructing operations.","Add a schema check that flags malformed JSON strings before install runs."],"tags":["json","parsing","install","operations"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}