{"record":{"id":"d1fa370d31ac4b08","repo":"mermaid-js/mermaid","slug":"the-group-id-id-is-already-in-use-by-another","errorCode":null,"errorMessage":"The group id [${id}] is already in use by another ${this.registeredIds.get(id)}","messagePattern":"The group id \\[(.+?)\\] is already in use by another (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/architecture/architectureDb.ts","lineNumber":162,"sourceCode":"      in: parent,\n    });\n  }\n\n  public getJunctions(): ArchitectureJunction[] {\n    return [...this.nodes.values()].filter(isArchitectureJunction);\n  }\n\n  public getNodes(): ArchitectureNode[] {\n    return [...this.nodes.values()];\n  }\n\n  public getNode(id: string): ArchitectureNode | null {\n    return this.nodes.get(id) ?? null;\n  }\n\n  public addGroup({ id, icon, in: parent, title }: ArchitectureGroup): void {\n    if (this.registeredIds.has(id)) {\n      throw new Error(\n        `The group 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 group [${id}] cannot be placed within itself`);\n      }\n      if (!this.registeredIds.has(parent)) {\n        throw new Error(\n          `The group [${id}]'s parent does not exist. Please make sure the parent is created before this group`\n        );\n      }\n      if (this.registeredIds.get(parent) === 'node') {\n        throw new Error(`The group [${id}]'s parent is not a group`);\n      }\n    }\n\n    this.registeredIds.set(id, 'group');","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/architecture/architectureDb.ts#L144-L180","documentation":"Thrown by addGroup when the group id already exists in registeredIds. Groups share the id namespace with services and junctions, so a collision with any prior entity trips this; the suffix ('node' or 'group') indicates the prior owner type.","triggerScenarios":"addGroup with an id already used by another group, a service, or a junction; defining two groups with the same id.","commonSituations":"Duplicate group labels in user text, generated specs with non-unique group ids, or a group id reused as a service id.","solutions":["Give each group a unique id; namespace if labels repeat.","Check db.getGroups()/registeredIds before adding.","If a clash is intentional, rename one entity and keep the title for display."],"exampleFix":"// before\ndb.addGroup({ id: 'net' });\ndb.addGroup({ id: 'net' }); // throws\n\n// after\ndb.addGroup({ id: 'net1', title: 'net' });\ndb.addGroup({ id: 'net2', title: 'net' });","handlingStrategy":"validation","validationCode":"if (db.getGroups().some((g) => g.id === id) || db.getNode(id) !== null) {\n  throw new Error(`id '${id}' already in use`);\n}\ndb.addGroup({ id });","typeGuard":"function isGroupIdFree(db: ArchitectureDB, id: string): boolean {\n  return db.getNode(id) === null && !db.getGroups().some((g) => g.id === id);\n}","tryCatchPattern":null,"preventionTips":["Check both nodes and groups for the id before addGroup.","Namespace group ids to avoid collisions with services/junctions.","Dedupe ids in any spec generator before insertion."],"tags":["architecture","mermaid","validation","duplicate-id","group"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}