{"record":{"id":"9d799457d46dbe48","repo":"calcom/cal.diy","slug":"unable-to-create-user-credential-for-alby","errorCode":null,"errorMessage":"Unable to create user credential for Alby","messagePattern":"Unable to create user credential for Alby","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/app-store/alby/api/add.ts","lineNumber":33,"sourceCode":"      where: {\n        type: appType,\n        userId: req.session.user.id,\n      },\n    });\n    if (alreadyInstalled) {\n      throw new Error(\"Already installed\");\n    }\n    const installation = await prisma.credential.create({\n      data: {\n        type: appType,\n        key: {},\n        userId: req.session.user.id,\n        appId: \"alby\",\n      },\n    });\n\n    if (!installation) {\n      throw new Error(\"Unable to create user credential for Alby\");\n    }\n  } catch (error: unknown) {\n    const httpError = getServerErrorFromUnknown(error);\n    return res.status(httpError.statusCode).json({ message: httpError.message });\n  }\n\n  return res.status(200).json({ url: \"/apps/alby/setup\" });\n}\n","sourceCodeStart":15,"sourceCodeEnd":42,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/packages/app-store/alby/api/add.ts#L15-L42","documentation":"Defensive guard thrown when prisma.credential.create returns a falsy value. In practice Prisma's create() throws on failure rather than returning null, so this branch is effectively unreachable; reaching it indicates an ORM/return-shape anomaly or a misbehaving mock.","triggerScenarios":"A unit test mocks prisma.credential.create to return undefined; a Prisma extension or middleware swallows the insert and returns null; a future refactor swaps create for a method with a different return shape.","commonSituations":"Test mocks of prisma.credential.create that forget to return a record; custom Prisma client extensions intercepting the call.","solutions":["If mocking prisma.credential.create, ensure the mock resolves to a truthy credential object.","Inspect the DB to confirm the row was actually written.","Treat this error as a signal that the create() return contract changed and update the guard accordingly."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"const created = await prisma.credential.create({ data });\nif (!created) {\n  // unexpected - log and surface a clearer error than the guard\n}","typeGuard":"const isCredential = (c: unknown): c is { id: number } =>\n  typeof c === 'object' && c !== null && typeof (c as any).id === 'number';","tryCatchPattern":null,"preventionTips":["In tests, mock prisma.credential.create to return a truthy record.","Do not rely on create() returning null - Prisma throws on failure; let it throw.","If you refactor to createMany/upsert, update this guard accordingly."],"tags":["alby","prisma","dead-code","credential"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}