{"record":{"id":"278976ba58330018","repo":"toeverything/AFFiNE","slug":"user-not-found-278976","errorCode":"user_not_found","errorMessage":"User not found.","messagePattern":"User not found\\.","errorType":"exception","errorClass":"UserNotFound","httpStatus":404,"severity":"error","filePath":"packages/backend/server/src/plugins/payment/manager/common.ts","lineNumber":289,"sourceCode":"      amount: stripeInvoice.total,\n      currency: stripeInvoice.currency,\n      lastPaymentError: error,\n    };\n  }\n\n  async getOrCreateCustomer(userId: string): Promise<UserStripeCustomer> {\n    const user = await this.db.user.findUnique({\n      where: {\n        id: userId,\n      },\n      select: {\n        email: true,\n        userStripeCustomer: true,\n      },\n    });\n\n    if (!user) {\n      throw new UserNotFound();\n    }\n\n    let customer = user.userStripeCustomer;\n    if (!customer) {\n      const stripeCustomersList = await this.stripe.customers.list({\n        email: user.email,\n        limit: 1,\n      });\n\n      let stripeCustomer: Stripe.Customer | undefined;\n      if (stripeCustomersList.data.length) {\n        stripeCustomer = stripeCustomersList.data[0];\n      } else {\n        stripeCustomer = await this.stripe.customers.create({\n          email: user.email,\n        });\n      }\n","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/backend/server/src/plugins/payment/manager/common.ts#L271-L307","documentation":"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.","triggerScenarios":"Thrown at packages/backend/server/src/plugins/payment/manager/common.ts:289 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the user id or email refers to an existing account.","Create the user account first if it has not been registered.","Check that the request targets the correct user and that the account was not deleted."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}