prisma-erd-generator icon indicating copy to clipboard operation
prisma-erd-generator copied to clipboard

Issue with UK enum value

Open guydunton opened this issue 1 year ago • 3 comments

I've found an issue with generation when an enum contains the value UK. e.g.

enum DeploymentRegions {
  EU
  UK
}

I get an error which looks like:

Command failed: "/Users/test/Documents/dev/api/node_modules/.bin/mmdc" -i "/var/folders/ky/5jpl226x1671bz_34h02wwg40000gn/T/prisma-erd-EtD1ko/prisma.mmd" -o "/Users/test/Documents/dev/api/prisma/ERD.svg" -c "/var/folders/ky/5jpl226x1671bz_34h02wwg40000gn/T/prisma-erd-EtD1ko/config.json" -p "/var/folders/ky/5jpl226x1671bz_34h02wwg40000gn/T/prisma-erd-EtD1ko/puppeteerConfig.json"

Running the command I get:

Error: Evaluation failed: Error: Parse error on line 28:
...     EU EUAP APUK UKNA NALA LAME ME
---------------------^
Expecting 'BLOCK_STOP', 'ATTRIBUTE_WORD', 'COMMA', 'COMMENT', got 'ATTRIBUTE_KEY'
    at aA.parseError (file:///Users/test/Documents/dev/api/node_modules/@mermaid-js/mermaid-cli/dist/index.html:226:13183)
    at aA.parse (file:///Users/test/Documents/dev/api/node_modules/@mermaid-js/mermaid-cli/dist/index.html:228:179)
    at HUe.parser.parse (file:///Users/test/Documents/dev/api/node_modules/@mermaid-js/mermaid-cli/dist/index.html:81:260)
    at HUe.parse (file:///Users/test/Documents/dev/api/node_modules/@mermaid-js/mermaid-cli/dist/index.html:81:498)
    at new HUe (file:///Users/test/Documents/dev/api/node_modules/@mermaid-js/mermaid-cli/dist/index.html:81:339)
    at yjA (file:///Users/test/Documents/dev/api/node_modules/@mermaid-js/mermaid-cli/dist/index.html:81:804)
    at async Object.jDt [as render] (file:///Users/test/Documents/dev/api/node_modules/@mermaid-js/mermaid-cli/dist/index.html:88:574)
    at ExecutionContext._ExecutionContext_evaluate (file:///Users/test/Documents/dev/api/node_modules/puppeteer-core/lib/esm/puppeteer/common/ExecutionContext.js:254:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async ExecutionContext.evaluate (file:///Users/test/Documents/dev/api/node_modules/puppeteer-core/lib/esm/puppeteer/common/ExecutionContext.js:143:16)
    at async CDPJSHandle.evaluate (file:///Users/test/Documents/dev/api/node_modules/puppeteer-core/lib/esm/puppeteer/common/JSHandle.js:56:16)
    at async CDPElementHandle.$eval (file:///Users/test/Documents/dev/api/node_modules/puppeteer-core/lib/esm/puppeteer/common/ElementHandle.js:86:24)
    at async renderMermaid (file:///Users/test/Documents/dev/api/node_modules/@mermaid-js/mermaid-cli/src/index.js:246:22)
    at async parseMMD (file:///Users/test/Documents/dev/api/node_modules/@mermaid-js/mermaid-cli/src/index.js:218:20)
    at async run (file:///Users/test/Documents/dev/api/node_modules/@mermaid-js/mermaid-cli/src/index.js:479:20)
    at async cli (file:///Users/test/Documents/dev/api/node_modules/@mermaid-js/mermaid-cli/src/index.js:184:3)

It looks to be related to mermaids using UK to indicate unique key (link).

We've gotten around it by disabling enum generation but a fix would be nice, either by escaping the value in the .mmd file (I couldn't see if this was possible) or by moving away from mermaids (as a fix to #102)

guydunton avatar Oct 04 '23 08:10 guydunton

Most of the time its a mermaid thing. I'll see if I haven't wrapped enums in quotes already. That's typically the route to get around some mermaid specifics.

keonik avatar Oct 04 '23 20:10 keonik

Gave it a shot and it looks like the enums were not wrapped in quotes already. When I wrote out a schema

generator erd {
  provider = "node ./dist/index.js"
  output   = "../../__tests__/238.png"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Deployment {
  id        String   @id @default(uuid()) @db.Uuid
    region DeploymentRegions
}

enum DeploymentRegions {
  EU
  UK
}

and ran locally with the quotes I was still getting an error. As it turns out the enums are not something you can wrap in quotes. All cases started to fail afterwards that used enums. I did get the above to pass by switching UK to anything else so it might be a reserved word for mermaid.

keonik avatar Oct 17 '23 16:10 keonik

What could be done is

  • Disabling enums in the output
generator erd {
  ...
  ignoreEnums = true
}
  • Asking maintainer to overwrite UK to U_K or something of that variety

What are your thoughts?

keonik avatar Oct 17 '23 16:10 keonik