{"record":{"id":"cd5d5680cb0121f5","repo":"mermaid-js/mermaid","slug":"the-destroyed-participant-this-state-records-las","errorCode":null,"errorMessage":"The destroyed participant ${this.state.records.lastDestroyed.name} does not have an associated destroying message after its declaration. Please check the sequence diagram.","messagePattern":"The destroyed participant (.+?) does not have an associated destroying message after its declaration\\. Please check the sequence diagram\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/sequence/sequenceDb.ts","lineNumber":638,"sourceCode":"          this.addDetails(param.actor, param.text);\n          break;\n        case 'addMessage':\n          if (this.state.records.lastCreated) {\n            if (param.to !== this.state.records.lastCreated) {\n              throw new Error(\n                'The created participant ' +\n                  this.state.records.lastCreated.name +\n                  ' does not have an associated creating message after its declaration. Please check the sequence diagram.'\n              );\n            } else {\n              this.state.records.lastCreated = undefined;\n            }\n          } else if (this.state.records.lastDestroyed) {\n            if (\n              param.to !== this.state.records.lastDestroyed &&\n              param.from !== this.state.records.lastDestroyed\n            ) {\n              throw new Error(\n                'The destroyed participant ' +\n                  this.state.records.lastDestroyed.name +\n                  ' does not have an associated destroying message after its declaration. Please check the sequence diagram.'\n              );\n            } else {\n              this.state.records.lastDestroyed = undefined;\n            }\n          }\n          this.addSignal(\n            param.from,\n            param.to,\n            param.msg,\n            param.signalType,\n            param.activate,\n            param.centralConnection\n          );\n          break;\n        case 'boxStart':","sourceCodeStart":620,"sourceCodeEnd":656,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/sequence/sequenceDb.ts#L620-L656","documentation":"Symmetric to the create case: after `destroy Participant`, lastDestroyed is set and the next message must involve that participant as either sender or receiver. If neither `from` nor `to` matches, the destroy is orphaned and mermaid throws.","triggerScenarios":"A `destroy` directive followed by a message that does not include the destroyed actor as sender or recipient, or by a non-message statement.","commonSituations":"Adding commentary or another statement right after `destroy`; reordering lines; typos in the destroyed id; tooling that separates `destroy` from its closing message.","solutions":["Ensure the message right after `destroy X` has X as `from` or `to`.","Drop the `destroy` if you do not need an explicit destroying message.","Keep `destroy` adjacent to the message that ends the lifeline.","Verify the destroyed id matches the message endpoint exactly."],"exampleFix":"// before\ndestroy Bob\nAlice ->> Charlie : bye  // Bob not involved\n\n// after\ndestroy Bob\nBob ->> Alice : bye","handlingStrategy":"validation","validationCode":"// Structural check: a destroy must be followed by a message involving that actor\nfor (let i = 0; i < lines.length; i++) {\n  if (/^\\s*destroy\\s+(\\S+)/.test(lines[i])) {\n    const id = RegExp.$1;\n    const next = lines[i + 1];\n    if (!next || !new RegExp(id).test(next)) {\n      throw new Error(`destroy ${id} not followed by a message involving ${id}`);\n    }\n  }\n}","typeGuard":"const isDestroyOrphanError = (e): boolean =>\n  e instanceof Error && /destroyed participant .* does not have an associated destroying message/.test(e.message);","tryCatchPattern":"try {\n  await mermaid.run({ nodes: [el] });\n} catch (e) {\n  if (e instanceof Error && /destroyed participant .* does not have/.test(e.message)) {\n    // make the next message send from or to the destroyed actor\n  } else { throw e; }\n}","preventionTips":["Keep `destroy X` adjacent to a message that involves X.","Don't separate destroy from its closing message.","Drop `destroy` if no explicit destroying message is intended."],"tags":["sequence","participant","destroy","message-flow","validation"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}