{"record":{"id":"f574f740f2d48baa","repo":"calcom/cal.diy","slug":"unable-to-create-user-credential-for-type-apptyp","errorCode":null,"errorMessage":"Unable to create user credential for type ${appType}","messagePattern":"Unable to create user credential for type (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/app-store/_utils/installation.ts","lineNumber":55,"sourceCode":"  key = {},\n  teamId,\n  billingCycleStart,\n  paymentStatus,\n  subscriptionId,\n}: InstallationArgs) {\n  const installation = await prisma.credential.create({\n    data: {\n      type: appType,\n      key,\n      ...(teamId ? { teamId } : { userId: user.id }),\n      appId: slug,\n      subscriptionId,\n      paymentStatus,\n      billingCycleStart,\n    },\n  });\n  if (!installation) {\n    throw new Error(`Unable to create user credential for type ${appType}`);\n  }\n  return installation;\n}\n","sourceCodeStart":37,"sourceCodeEnd":59,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/packages/app-store/_utils/installation.ts#L37-L59","documentation":"Thrown by createDefaultInstallation when prisma.credential.create returns a falsy value. In practice Prisma's create throws on failure rather than returning null, so this guard is defensive and rarely fires. If it does, it means the DB layer returned an unexpected empty result for the insert.","triggerScenarios":"prisma.credential.create completes without throwing but resolves to null/undefined. Theoretically possible with a custom Prisma client interceptor, a DB driver quirk, or a malformed input that Prisma silently coerces to nothing. Almost never seen with stock Prisma.","commonSituations":"A Prisma extension/middleware that swallows the insert and returns null; a DB connection that dropped mid-write in a way Prisma did not surface as a throw; extremely rare driver bug; testing with a mocked prisma that returns undefined.","solutions":["Check server logs for the underlying Prisma behavior; a real create failure usually throws first.","If using Prisma extensions/middleware, ensure they return the created record.","Verify DB connectivity and that the credential table accepts the insert (constraints, column types).","In tests, make sure the mocked prisma.credential.create resolves to a truthy object."],"exampleFix":"// before - mock returns undefined\nprisma.credential.create = jest.fn().mockResolvedValue(undefined);\n// after - mock returns the created record\nprisma.credential.create = jest.fn().mockResolvedValue({ id: 1, type: 'zoom', appId: 'zoom' });","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  return await prisma.credential.create({ data: { ... } });\n} catch (dbError) {\n  // Prisma throws on real failures; surface the actual DB error\n  throw new Error(`Credential create failed: ${dbError.message}`);\n}","preventionTips":["Inspect server logs: real create failures surface as thrown Prisma errors, not this guard.","Ensure Prisma extensions/middleware return the created record.","In tests, mock prisma.credential.create to resolve to a truthy object."],"tags":["credentials","prisma","database","defensive"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}