{"record":{"id":"74caa83ff7343e72","repo":"mermaid-js/mermaid","slug":"the-junction-id-cannot-be-placed-within-itsel","errorCode":null,"errorMessage":"The junction [${id}] cannot be placed within itself","messagePattern":"The junction \\[(.+?)\\] cannot be placed within itself","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/architecture/architectureDb.ts","lineNumber":126,"sourceCode":"      title,\n      edges: [],\n      in: parent,\n    });\n  }\n\n  public getServices(): ArchitectureService[] {\n    return [...this.nodes.values()].filter(isArchitectureService);\n  }\n\n  public addJunction({ id, in: parent }: Omit<ArchitectureJunction, 'edges'>): void {\n    if (this.registeredIds.has(id)) {\n      throw new Error(\n        `The junction id [${id}] is already in use by another ${this.registeredIds.get(id)}`\n      );\n    }\n    if (parent !== undefined) {\n      if (id === parent) {\n        throw new Error(`The junction [${id}] cannot be placed within itself`);\n      }\n      if (!this.registeredIds.has(parent)) {\n        throw new Error(\n          `The junction [${id}]'s parent does not exist. Please make sure the parent is created before this junction`\n        );\n      }\n      if (this.registeredIds.get(parent) === 'node') {\n        throw new Error(`The junction [${id}]'s parent is not a group`);\n      }\n    }\n\n    this.registeredIds.set(id, 'node');\n\n    this.nodes.set(id, {\n      id,\n      type: 'junction',\n      edges: [],\n      in: parent,","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/architecture/architectureDb.ts#L108-L144","documentation":"Thrown by addJunction when its parent ('in') equals its own id, mirroring the self-containment guard on services. A junction cannot be its own container, so the db rejects id === parent before registration.","triggerScenarios":"addJunction({ id: 'X', in: 'X' }); or generated layout hint that lists a junction as its own parent.","commonSituations":"Programmatic spec builder assigns the same id to a junction and its parent slot, or a templating copy bug.","solutions":["Ensure parent id differs from the junction id.","Drop the 'in' field for a top-level junction.","Validate id !== parent before addJunction."],"exampleFix":"// before\ndb.addJunction({ id: 'j', in: 'j' });\n\n// after\ndb.addJunction({ id: 'j' });","handlingStrategy":"validation","validationCode":"if (id === parent) {\n  throw new Error(`Junction '${id}' cannot be its own parent`);\n}\ndb.addJunction({ id, in: parent });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep parent assignment independent of the junction id.","Omit 'in' for top-level junctions."],"tags":["architecture","mermaid","validation","cycle","junction"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}