{"record":{"id":"dccb2e87f1287efe","repo":"affaan-m/ECC","slug":"malformed-coordination-json-in-body-error-messa","errorCode":null,"errorMessage":"Malformed coordination JSON in body: ${error.message} — raw: ${match[1].slice(0, 120)}","messagePattern":"Malformed coordination JSON in body: (.+?) — raw: (.+?)","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"scripts/lib/github-coordination/parsing.js","lineNumber":26,"sourceCode":"\nfunction normalizeBodyForComparison(body) {\n  return (body || '').replace(/\"lastSyncAt\"\\s*:\\s*[^,}\\n]+/g, '\"lastSyncAt\": NORMALIZED');\n}\n\nfunction extractCoordinationState(body, policy = DEFAULT_POLICY) {\n  const marker = escapeRegExp(policy.sectionMarker || DEFAULT_SECTION_MARKER);\n  const regex = new RegExp(`<!--\\\\s*${marker}:start\\\\s*-->\\\\s*` + '```json\\\\s*([\\\\s\\\\S]*?)\\\\s*```' + `\\\\s*<!--\\\\s*${marker}:end\\\\s*-->`, 'm');\n  const match = String(body || '').match(regex);\n\n  if (!match) {\n    return null;\n  }\n\n  try {\n    const parsed = JSON.parse(match[1]);\n    return parsed && typeof parsed === 'object' ? parsed : null;\n  } catch (error) {\n    throw new SyntaxError(`Malformed coordination JSON in body: ${error.message} — raw: ${match[1].slice(0, 120)}`);\n  }\n}\n\nfunction extractIssueReferences(text) {\n  const refs = new Set();\n  const source = String(text || '');\n  for (const match of source.matchAll(/(?:^|[^\\d])#(\\d+)\\b/g)) {\n    refs.add(Number.parseInt(match[1], 10));\n  }\n  return Array.from(refs)\n    .filter(Number.isFinite)\n    .sort((a, b) => a - b);\n}\n\nfunction extractTasks(body) {\n  const lines = String(body || '').split(/\\r?\\n/);\n  const tasks = [];\n  let inTasks = false;","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/github-coordination/parsing.js#L8-L44","documentation":"extractCoordinationState finds an embedded coordination JSON block in an issue/PR body and throws a SyntaxError when that block fails JSON.parse. The message includes the underlying parse error plus the first 120 characters of the raw block to help locate the corruption. The library throws rather than silently ignoring the block because the coordination state is authoritative for claim/conflict decisions.","triggerScenarios":"Calling getCoordinationState (or functions that read state from a body) when the fenced coordination JSON in the body was hand-edited, truncated, contains trailing commas/comments, or was mangled by another tool.","commonSituations":"Manual edits to the issue body that break the JSON (missing brace/quote), markdown formatters or GitHub UI edits reflowing the block, automation writing partial state before crashing, or copying the block from another issue with encoding damage.","solutions":["Read the 'raw:' excerpt in the message to find the exact JSON syntax error.","Fix the coordination JSON block in the issue/PR body (validate with a JSON linter before saving).","Restore the block by re-running the command that originally wrote the coordination state.","If the block is unrecoverable, remove it and let the library re-initialize fresh coordination state."],"exampleFix":"// before (in issue body)\n<!-- ecc:coordination -->{\"status\": \"claimed\",, \"owner\": \"alice\"}\n// after\n<!-- ecc:coordination -->{\"status\": \"claimed\", \"owner\": \"alice\"}","handlingStrategy":"validation","validationCode":"function isParseableJson(s) {\n  try { JSON.parse(s); return true; } catch { return false; }\n}\nconst block = body.match(/<!--\\s*ecc:coordination\\s*-->([\\s\\S]*?)<!--\\s*\\/ecc:coordination\\s*-->/);\nif (block && !isParseableJson(block[1])) throw new Error('Coordination block JSON is malformed; fix the issue body');","typeGuard":"const isCoordinationState = (v) => v !== null && typeof v === 'object' && !Array.isArray(v) && typeof v.status === 'string';","tryCatchPattern":"let state;\ntry {\n  state = extractCoordinationState(body);\n} catch (e) {\n  if (e instanceof SyntaxError && e.message.startsWith('Malformed coordination JSON')) {\n    console.error('Fix the coordination JSON block in the issue body:', e.message);\n    state = null;\n  } else { throw e; }\n}","preventionTips":["Never hand-edit the coordination JSON block; use the CLI commands that write it.","Validate JSON with a linter before saving issue-body edits.","Keep the fenced block intact when reformatting markdown.","Re-run the state-writing command to regenerate corrupted blocks."],"tags":["json","parsing","issue-body"],"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"}