calcom/cal.diy · error · Error

Unable to create user credential for Alby

Error message

Unable to create user credential for Alby

What it means

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.

Source

Thrown at packages/app-store/alby/api/add.ts:33

      where: {
        type: appType,
        userId: req.session.user.id,
      },
    });
    if (alreadyInstalled) {
      throw new Error("Already installed");
    }
    const installation = await prisma.credential.create({
      data: {
        type: appType,
        key: {},
        userId: req.session.user.id,
        appId: "alby",
      },
    });

    if (!installation) {
      throw new Error("Unable to create user credential for Alby");
    }
  } catch (error: unknown) {
    const httpError = getServerErrorFromUnknown(error);
    return res.status(httpError.statusCode).json({ message: httpError.message });
  }

  return res.status(200).json({ url: "/apps/alby/setup" });
}

View on GitHub (pinned to 176037d0af)

Solutions

  1. If mocking prisma.credential.create, ensure the mock resolves to a truthy credential object.
  2. Inspect the DB to confirm the row was actually written.
  3. Treat this error as a signal that the create() return contract changed and update the guard accordingly.
Defensive patterns

Strategy: type-guard

Validate before calling

const created = await prisma.credential.create({ data });
if (!created) {
  // unexpected - log and surface a clearer error than the guard
}

Type guard

const isCredential = (c: unknown): c is { id: number } =>
  typeof c === 'object' && c !== null && typeof (c as any).id === 'number';

Prevention

When it happens

Trigger: 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.

Common situations: Test mocks of prisma.credential.create that forget to return a record; custom Prisma client extensions intercepting the call.

Related errors


AI-assisted analysis of calcom/cal.diy@176037d0af (2026-08-12). Data as JSON: /api/errors/9d799457d46dbe48. Report an issue: GitHub.