{"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/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/lib/github-coordination/parsing.js#L8-L44","documentation":"Thrown as a SyntaxError by extractCoordinationState (parsing.js) when the coordination JSON block inside an issue body is found (the marker-delimited ```json fence matches) but its contents fail JSON.parse. This indicates the embedded coordination state was hand-edited or corrupted — the structure is recognizable but the payload is invalid JSON, so it cannot be read or updated safely.","triggerScenarios":"A user edited the coordination block in the issue body and introduced a syntax error (trailing comma, unquoted key, missing brace); a bot wrote a truncated block; mixed smart-quotes; a copy-paste dropped a character.","commonSituations":"Manual edits to the coordination section; a tool that writes partial/async state got interrupted; an editor auto-'corrected' quotes; locale-specific punctuation in JSON.","solutions":["Open the issue body and fix the JSON inside the coordination:start/coordination:end fence; the message shows the first 120 chars of the offending payload.","Validate the block with a JSON linter before saving the issue body.","Use the coordination tooling to write the block rather than editing it by hand, so it is always valid.","If the block is unrecoverable, regenerate it via the coordination state builder from the issue's labels/refs."],"exampleFix":"// before (in the issue body)\n<!-- coordination:start -->\n```json\n{ \"status\": \"draft\", \"dependencies\": [12, 13, }  // <- stray comma + unclosed brace\n```\n<!-- coordination:end -->\n\n// after\n<!-- coordination:start -->\n```json\n{ \"status\": \"draft\", \"dependencies\": [12, 13] }\n```\n<!-- coordination:end -->","handlingStrategy":"try-catch","validationCode":"function safeExtract(body) {\n  try { return extractCoordinationState(body); }\n  catch (e) { if (e instanceof SyntaxError) { console.warn('coordination block malformed — will regenerate'); return null; } throw e; }\n}","typeGuard":"function isJsonObject(v) {\n  return v !== null && typeof v === 'object' && !Array.isArray(v);\n}","tryCatchPattern":"try {\n  extractCoordinationState(body);\n} catch (e) {\n  if (e instanceof SyntaxError && /Malformed coordination JSON/.test(e.message)) {\n    // regenerate the block from labels/refs rather than trusting the broken body\n    return rebuildCoordinationBlock(issue);\n  }\n  throw e;\n}","preventionTips":["Edit coordination blocks only through the tooling, never by hand.","Validate the JSON with a linter before saving the issue body.","Use straight quotes and no trailing commas in the embedded JSON."],"tags":["github-coordination","parsing","json","issue-body","syntax"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}