toeverything/AFFiNE · error · UserNotFound

user_not_found

user_not_found

Error message

User not found.

What it means

A UserNotFound sentinel thrown by getOrCreateCustomer when the Prisma lookup for the given userId returns no row (the select only fetches email and userStripeCustomer). It means the payment manager was asked to create/reuse a Stripe customer for a user id that does not exist in the database — typically a stale or forged userId reaching the billing flow.

Source

Thrown at packages/backend/server/src/plugins/payment/manager/common.ts:289

      amount: stripeInvoice.total,
      currency: stripeInvoice.currency,
      lastPaymentError: error,
    };
  }

  async getOrCreateCustomer(userId: string): Promise<UserStripeCustomer> {
    const user = await this.db.user.findUnique({
      where: {
        id: userId,
      },
      select: {
        email: true,
        userStripeCustomer: true,
      },
    });

    if (!user) {
      throw new UserNotFound();
    }

    let customer = user.userStripeCustomer;
    if (!customer) {
      const stripeCustomersList = await this.stripe.customers.list({
        email: user.email,
        limit: 1,
      });

      let stripeCustomer: Stripe.Customer | undefined;
      if (stripeCustomersList.data.length) {
        stripeCustomer = stripeCustomersList.data[0];
      } else {
        stripeCustomer = await this.stripe.customers.create({
          email: user.email,
        });
      }

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Verify the user id or email refers to an existing account.
  2. Create the user account first if it has not been registered.
  3. Check that the request targets the correct user and that the account was not deleted.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/backend/server/src/plugins/payment/manager/common.ts:289 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class

Background: "User not found", "Invalid user", and "does not exist": what missing-user lookup errors mean across Rocket.Chat, LiteLLM, Phabricator, rustfs, and pnpm — this error's family across 10 libraries.


AI-assisted analysis of toeverything/AFFiNE@b4c8548c09 (2026-08-18). Data as JSON: /api/errors/278976ba58330018. Report an issue: GitHub.