{"record":{"id":"686b1c665e322f57","repo":"sickn33/agentic-awesome-skills","slug":"user-userid-not-found","errorCode":null,"errorMessage":"User ${userId} not found","messagePattern":"User (.+?) not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"skills/fp-refactor/SKILL.md","lineNumber":682,"sourceCode":"\ninterface EmailService {\n  send(to: string, subject: string, body: string): Promise<void>;\n}\n\nclass UserService {\n  constructor(\n    private readonly logger: Logger,\n    private readonly userRepo: UserRepository,\n    private readonly emailService: EmailService\n  ) {}\n\n  async updateEmail(userId: string, newEmail: string): Promise<void> {\n    this.logger.log(`Updating email for user ${userId}`);\n\n    const user = await this.userRepo.findById(userId);\n    if (!user) {\n      this.logger.error(`User ${userId} not found`);\n      throw new Error(`User ${userId} not found`);\n    }\n\n    const oldEmail = user.email;\n    user.email = newEmail;\n\n    await this.userRepo.save(user);\n\n    await this.emailService.send(\n      oldEmail,\n      'Email Changed',\n      `Your email has been changed to ${newEmail}`\n    );\n\n    this.logger.log(`Email updated for user ${userId}`);\n  }\n}\n\n// Manual DI setup","sourceCodeStart":664,"sourceCodeEnd":700,"githubUrl":"https://github.com/sickn33/agentic-awesome-skills/blob/58d857988fcfac6986206bca2b2fe223aa437e4b/skills/fp-refactor/SKILL.md#L664-L700","documentation":"In fp-refactor's OO example, UserService.updateEmail throws (and logs) this when userRepo.findById resolves falsy for the given userId. It is a business-layer not-found guard before mutating the user entity.","triggerScenarios":"Calling updateEmail with a deleted user's id, a wrong-environment id, or an id race where the user is removed between screen load and save.","commonSituations":"Admin dashboards editing archived users; stale SPA state after another admin deletes the account; repository returning null for soft-deleted rows while the UI still lists them.","solutions":["Verify the user still exists before showing the edit form (or refresh on save)","Map this throw to a 404 response at the controller boundary instead of a 500","Return TaskEither<DomainError, void> with a UserNotFound tagged error per the skill's refactor"],"exampleFix":"// before\nconst user = await this.userRepo.findById(userId)\nif (!user) throw new Error(`User ${userId} not found`)\n\n// after: tagged, typed failure\ntype DomainError = { _tag: 'UserNotFound'; userId: string } | { _tag: 'RepoError'; cause: Error }\nconst user = await this.userRepo.findById(userId)\nif (!user) return E.left<DomainError, void>({ _tag: 'UserNotFound', userId })","handlingStrategy":"try-catch","validationCode":"// before showing an edit form:\nconst exists = await userRepo.findById(userId)\nif (!exists) throw new Response('User not found', { status: 404 })","typeGuard":null,"tryCatchPattern":"try {\n  await userService.updateEmail(userId, email)\n} catch (e) {\n  if (e instanceof Error && /not found/.test(e.message)) {\n    return res.status(404).json({ error: 'User not found' })\n  }\n  throw e\n}","preventionTips":["Refresh entity existence before edits in long-lived screens","Map not-found throws to 404 at the controller, never 500"],"tags":["not-found","repository","business-logic","async"],"backgroundTag":"resource-not-found","analyzedSha":"58d857988fcfac6986206bca2b2fe223aa437e4b","analyzedAt":"2026-08-26T11:55:59.350Z","schemaVersion":2},"datasetVersion":"2026-08-26T14:46:13.012Z"}