{"record":{"id":"6f5b180373e327ab","repo":"langfuse/langfuse","slug":"failed-to-create-prompt","errorCode":null,"errorMessage":"Failed to create prompt","messagePattern":"Failed to create prompt","errorType":"exception","errorClass":"Error","httpStatus":500,"severity":"error","filePath":"web/src/features/prompts/server/routers/promptRouter.ts","lineNumber":343,"sourceCode":"          projectId: input.projectId,\n          scope: \"promptProtectedLabels:CUD\",\n          forbiddenErrorMessage: `You don't have permission to create a prompt with a protected label. Please contact your project admin for assistance.\\n\\n Protected labels are: ${protectedLabels.join(\", \")}`,\n        });\n      }\n\n      const prompt = await createPrompt({\n        ...input,\n        prisma: ctx.prisma,\n        createdBy: ctx.session.user.id,\n        user: {\n          id: ctx.session.user.id,\n          name: ctx.session.user.name ?? null,\n          email: ctx.session.user.email ?? null,\n        },\n      });\n\n      if (!prompt) {\n        throw new Error(\"Failed to create prompt\");\n      }\n\n      await auditLog(\n        {\n          session: ctx.session,\n          resourceType: \"prompt\",\n          resourceId: prompt.id,\n          action: \"create\",\n          after: prompt,\n        },\n        ctx.prisma,\n      );\n\n      return prompt;\n    }),\n  duplicatePrompt: protectedProjectProcedure\n    .input(\n      z.object({","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/langfuse/langfuse/blob/59d92c7cf365150d10b753b5a0d1708902a2ed60/web/src/features/prompts/server/routers/promptRouter.ts#L325-L361","documentation":"Thrown when a Prisma create() for a new prompt returns a falsy result in the promptCreate mutation. Prisma create() practically never returns null, so hitting this means the create call was skipped, returned early, or an unexpected runtime shape occurred. It is a defensive guard, not an expected business error.","triggerScenarios":"Calling the tRPC mutation prompts.create (promptRouter.ts:343) with valid session/project and the underlying prisma.prompt.create unexpectedly returning undefined.","commonSituations":"Almost never fires in practice; if it does, suspect a Prisma version change, a mocked/stubbed prisma client in tests, or a database write that silently failed.","solutions":["Check server logs for the surrounding Prisma call and any DB errors just before this throw","Verify the Prisma client version and that generated client matches packages/shared/prisma schema","If reproducible only in tests, ensure the test prisma mock returns a truthy object for prompt.create"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await trpc.prompts.create.mutate(input);\n} catch (e) {\n  if (e instanceof TRPCClientError && e.message === 'Failed to create prompt') {\n    // surface as internal error, check server logs\n  }\n  throw e;\n}","preventionTips":["Keep prisma client and generated code in sync with schema","In tests, make prisma.prompt.create mocks return a real object"],"tags":["prompts","trpc","prisma","internal-error"],"backgroundTag":"unexpected-null-db-result","analyzedSha":"59d92c7cf365150d10b753b5a0d1708902a2ed60","analyzedAt":"2026-08-27T22:22:00.402Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}