{"record":{"id":"ecf57ac47631bde8","repo":"mermaid-js/mermaid","slug":"class-not-found-id","errorCode":null,"errorMessage":"Class not found: ${id}","messagePattern":"Class not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/class/classDb.ts","lineNumber":170,"sourceCode":"   */\n  public setDiagramId(svgElementId: string) {\n    this.diagramId = svgElementId;\n  }\n\n  /**\n   * Function to lookup domId from id in the graph definition.\n   * When diagramId is set, returns the prefixed version for DOM uniqueness.\n   *\n   * @param id - class ID to lookup\n   * @public\n   */\n  public lookUpDomId(_id: string): string {\n    const id = common.sanitizeText(_id, getConfig());\n    if (this.classes.has(id)) {\n      const domId = this.classes.get(id)!.domId;\n      return this.diagramId ? `${this.diagramId}-${domId}` : domId;\n    }\n    throw new Error('Class not found: ' + id);\n  }\n\n  public clear() {\n    this.relations = [];\n    this.classes = new Map<string, ClassNode>();\n    this.notes = new Map<string, ClassNote>();\n    this.interfaces = [];\n    this.functions = [];\n    this.functions.push(this.setupToolTips.bind(this));\n    this.namespaces = new Map<string, NamespaceNode>();\n    this.namespaceCounter = 0;\n    this.namespaceStack = [];\n    this.diagramId = '';\n    this.direction = 'TB';\n    commonClear();\n  }\n\n  public getClass(id: string): ClassNode {","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/class/classDb.ts#L152-L188","documentation":"Thrown by ClassDB.lookUpDomId when the sanitized id is not present in the classes map. The method sanitizes the raw id via common.sanitizeText before lookup, so the id used for the miss may differ from what the caller passed (e.g. whitespace or disallowed characters stripped). It is the canonical way to resolve a class's DOM id for rendering, and a miss means no class with that (sanitized) name was ever declared.","triggerScenarios":"Calling db.lookUpDomId('Ghost') where 'Ghost' was never added via addClass. Also: calling lookUpDomId on an id whose sanitized form doesn't match any declared class — e.g. passing 'My Class' when the declared id is 'MyClass'.","commonSituations":"Referencing a class (in a relation, note, or annotation) before it is declared; typos or case mismatches; ids containing characters that sanitizeText strips or collapses, so the caller's string doesn't match the stored key.","solutions":["Declare the class (via addClass or the class DSL) before calling lookUpDomId.","Check the spelling and case of the id.","Remember the lookup uses the sanitized form — pass the same raw id form that was used at declaration so sanitization produces a matching key."],"exampleFix":"// before\ndb.lookUpDomId('Ghost'); // never declared\n// after\ndb.addClass('Ghost');\ndb.lookUpDomId('Ghost');","handlingStrategy":"validation","validationCode":"function lookUpDomIdSafe(db, id) {\n  if (!db.getClasses().has(id)) {\n    throw new Error(`Class '${id}' not declared; cannot look up domId`);\n  }\n  return db.lookUpDomId(id);\n}","typeGuard":"const classExists = (db, id) => db.getClasses().has(id);","tryCatchPattern":null,"preventionTips":["Declare classes before referencing them in relations, notes, or lookups.","Remember lookUpDomId sanitizes the id — pass the same raw form used at declaration."],"tags":["class","lookup","reference","sanitization"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}