{"record":{"id":"cb86227d1d0b4aa8","repo":"mermaid-js/mermaid","slug":"parser-parser-yy-was-not-a-packetdb-this-is-due","errorCode":null,"errorMessage":"parser.parser?.yy was not a PacketDB. This is due to a bug within Mermaid, please report this issue at https://github.com/mermaid-js/mermaid/issues.","messagePattern":"parser\\.parser\\?\\.yy was not a PacketDB\\. This is due to a bug within Mermaid, please report this issue at https://github\\.com/mermaid-js/mermaid/issues\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/packet/parser.ts","lineNumber":100,"sourceCode":"      bits: rowEnd - block.start,\n    },\n    {\n      start: rowStart,\n      end: block.end,\n      label: block.label,\n      bits: block.end - rowStart,\n    },\n  ];\n};\n\nexport const parser: ParserDefinition = {\n  // @ts-expect-error - PacketDB is not assignable to DiagramDB\n  parser: { yy: undefined },\n  parse: async (input: string): Promise<void> => {\n    const ast: Packet = await parse('packet', input);\n    const db = parser.parser?.yy;\n    if (!(db instanceof PacketDB)) {\n      throw new Error(\n        'parser.parser?.yy was not a PacketDB. This is due to a bug within Mermaid, please report this issue at https://github.com/mermaid-js/mermaid/issues.'\n      );\n    }\n    log.debug(ast);\n    populate(ast, db);\n  },\n};\n","sourceCodeStart":82,"sourceCodeEnd":108,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/packet/parser.ts#L82-L108","documentation":"Thrown by the packet parser's parse() when parser.parser.yy is not an instance of PacketDB. The yy field (a yacc convention meaning 'your variable') is supposed to be set by mermaid's diagram registration before parse runs, wiring the parser to its db. If that wiring didn't happen — e.g. the diagram type wasn't registered, or a custom integration called parse() directly without setting yy — the db is undefined or wrong-typed and parsing cannot proceed. The message itself directs users to report it as a mermaid bug.","triggerScenarios":"Calling parser.parse() directly without first assigning parser.parser.yy = new PacketDB(); a mermaid internal where diagram registration for 'packet' failed or was skipped; using a stale parser instance across diagram clears.","commonSituations":"Custom/programmatic use of mermaid's parser outside the standard mermaid.render() flow; SSR or test setups that import the parser in isolation; version mismatches between @mermaid-js/parser and the mermaid package.","solutions":["If using mermaid programmatically, call mermaid.parse()/mermaid.render() which handles yy wiring — do not invoke the packet parser directly.","Ensure @mermaid-js/parser and mermaid package versions are aligned (no mismatched installs).","If you must call the parser directly, set parser.parser.yy to a fresh PacketDB instance before parse().","Report upstream if this occurs through the standard mermaid.render() API."],"exampleFix":"// before — direct parser use, yy unset\nimport { parser } from './packet/parser.js';\nawait parser.parse(input);  // throws: yy not a PacketDB\n\n// after — let mermaid wire the db\nimport mermaid from 'mermaid';\nawait mermaid.parse('packet-beta\\n  0-7: Field A');","handlingStrategy":"type-guard","validationCode":"import { PacketDB } from './db.js';\nimport { parser } from './parser.js';\n\nif (!(parser.parser?.yy instanceof PacketDB)) {\n  parser.parser.yy = new PacketDB();\n}","typeGuard":"function isPacketDB(db: unknown): db is PacketDB {\n  return db instanceof PacketDB;\n}","tryCatchPattern":"try {\n  await mermaid.render('g', diagramText);\n} catch (e) {\n  if (e instanceof Error && /was not a PacketDB/.test(e.message)) {\n    showUserError('Packet diagram failed to initialize its database. Ensure you use mermaid.render() and that mermaid/parser versions match.');\n  } else throw e;\n}","preventionTips":["Use mermaid.render()/mermaid.parse() rather than calling the packet parser directly.","Keep @mermaid-js/parser and mermaid package versions in sync.","If calling the parser directly, always set parser.parser.yy to a PacketDB instance first."],"tags":["mermaid","packet","parsing","internal-invariant","integration"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}