Skip to content

Error when creating a duplicate tag #277

@Pacodastre

Description

@Pacodastre

Creating a tag that already exists gives an error from the server.

Steps to reproduce:

  1. Go to admin area, select Meta then Tags
  2. Create a tag, say action
  3. Create a second tag, also action
    4.. See results

Expected results:

The frontend informs the user there was an error creating the tag as it already exists

Actual result:

The button goes into a loading state and is stuck there. Clicking cancel on the modal closes the modal but shows another one hidden behind the first one with an error message. It is not possible to create other tags after that as the form is continuously in the loading state. You need either a page refresh or leaving and coming back to the page to be able to add another tag.

Image Image

Error logs:

ERROR  [request error] [unhandled] [POST] http://localhost:3000/api/v1/admin/tags                            20:05:51

 
ℹ Error: 
Invalid prisma.gameTag.create() invocation:


Unique constraint failed on the fields: (name)

 ⁃ at Jn.handleRequestError (node_modules/.pnpm/@prisma+client@6.12.0_prisma@6.12.0_typescript@5.8.3__typescript@5.8.3/node_modules/@prisma/client/runtime/library.mjs:128:7460)
 ⁃ at Jn.handleAndLogRequestError (node_modules/.pnpm/@prisma+client@6.12.0_prisma@6.12.0_typescript@5.8.3__typescript@5.8.3/node_modules/@prisma/client/runtime/library.mjs:128:6785)
 ⁃ at Jn.request (node_modules/.pnpm/@prisma+client@6.12.0_prisma@6.12.0_typescript@5.8.3__typescript@5.8.3/node_modules/@prisma/client/runtime/library.mjs:128:6492)
 ⁃ at async l (node_modules/.pnpm/@prisma+client@6.12.0_prisma@6.12.0_typescript@5.8.3__typescript@5.8.3/node_modules/@prisma/client/runtime/library.mjs:137:9767)
 ⁃ at async Object.handler (server/api/v1/admin/tags/index.post.ts:21:0)

   13 ┃  
   14 ┃    const body = await readDropValidatedBody(h3, CreateTag);
   15 ┃  
   16 ┃    const tag = await prisma.gameTag.create({
   17 ┃      data: {
   18 ┃        ...body,
   19 ┃      },
   20 ┃    });
 ❯ 21 ┃    return tag;
   22 ┃  });
   23 ┃  

 ⁃ (async file://node_modules/.pnpm/h3@1.15.3/node_modules/h3/dist/index.mjs:2003:19)
 ⁃ at async Object.callAsync (node_modules/.pnpm/unctx@2.4.1/node_modules/unctx/dist/index.mjs:72:16)
 ⁃ at async Server.toNodeHandle (node_modules/.pnpm/h3@1.15.3/node_modules/h3/dist/index.mjs:2295:7)

[CAUSE]
PrismaClientKnownRequestError {
  stack: '\n' +
  'Invalid prisma.gameTag.create() invocation:\n' +
  '\n' +
  '\n' +
  'Unique constraint failed on the fields: (name)\n' +
  'at Jn.handleRequestError (./node_modules/.pnpm/@prisma+client@6.12.0_prisma@6.12.0_typescript@5.8.3__typescript@5.8.3/node_modules/@prisma/client/runtime/library.mjs:128:7460)\n' +
  'at Jn.handleAndLogRequestError (./node_modules/.pnpm/@prisma+client@6.12.0_prisma@6.12.0_typescript@5.8.3__typescript@5.8.3/node_modules/@prisma/client/runtime/library.mjs:128:6785)\n' +
  'at Jn.request (./node_modules/.pnpm/@prisma+client@6.12.0_prisma@6.12.0_typescript@5.8.3__typescript@5.8.3/node_modules/@prisma/client/runtime/library.mjs:128:6492)\n' +
  'at async l (./node_modules/.pnpm/@prisma+client@6.12.0_prisma@6.12.0_typescript@5.8.3__typescript@5.8.3/node_modules/@prisma/client/runtime/library.mjs:137:9767)\n' +
  'at async Object.handler (./server/api/v1/admin/tags/index.post.ts:21:0)\n' +
  'at async file:///home/paco/Pro'... 326 more characters,
  message: '\n' +
  
  'Invalid prisma.gameTag.create() invocation:\n' +
  
  '\n' +
  
  '\n' +
  
  'Unique constraint failed on the fields: (name)',
  code: 'P2002',
  meta: {
    modelName: 'GameTag',
    target: [Array],
  },
  clientVersion: '6.12.0',
  batchRequestIdx: undefined,
  name: 'PrismaClientKnownRequestError',
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingconfirmedBug has been confirmed, or feature is on the roadmap.good first issueGood for newcomers

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions