[PR #4914] [MERGED] Fix: Clean username already exists error #4816

Closed
opened 2026-02-22 18:36:35 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Mintplex-Labs/anything-llm/pull/4914
Author: @angelplusultra
Created: 1/27/2026
Status: Merged
Merged: 1/29/2026
Merged by: @timothycarambat

Base: masterHead: 4912-bug-clean-username-already-exists-error


📝 Commits (2)

  • 40a9471 Add Prisma unique constraint error messaging.
  • 709c875 Create _identifyErrorAndFormatMessage private method for identifying the error type and returning the approprioate error message string

📊 Changes

1 file changed (+17 additions, -3 deletions)

View changed files

📝 server/models/user.js (+17 -3)

📄 Description

Pull Request Type

  • feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 🔨 chore
  • 📝 docs

Relevant Issues

resolves #4912

What is in this change?

Handles Prisma unique constraint violation errors (P2002) in the User model to return user-friendly error messages instead of raw Prisma error strings.

Before: Users see verbose Prisma errors like Unique constraint failed on the fields: ('username')

After: Users see clean messages like A user with that username already exists

Changes:

  • Added Prisma import from @prisma/client in server/models/user.js
  • Added P2002 error handling in User.create() method
  • Added P2002 error handling in User.update() method

Additional Information

This fix covers all user creation and update endpoints across the codebase (admin panel, API, invite acceptance, profile updates, etc.)

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated
  • I have tested my code functionality
  • Docker build succeeds locally

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Mintplex-Labs/anything-llm/pull/4914 **Author:** [@angelplusultra](https://github.com/angelplusultra) **Created:** 1/27/2026 **Status:** ✅ Merged **Merged:** 1/29/2026 **Merged by:** [@timothycarambat](https://github.com/timothycarambat) **Base:** `master` ← **Head:** `4912-bug-clean-username-already-exists-error` --- ### 📝 Commits (2) - [`40a9471`](https://github.com/Mintplex-Labs/anything-llm/commit/40a9471d40c826750c0ac20054a9a5cf7dfc6726) Add Prisma unique constraint error messaging. - [`709c875`](https://github.com/Mintplex-Labs/anything-llm/commit/709c875854521fe014030b32ded97fbfb1ea2c65) Create `_identifyErrorAndFormatMessage` private method for identifying the error type and returning the approprioate error message string ### 📊 Changes **1 file changed** (+17 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `server/models/user.js` (+17 -3) </details> ### 📄 Description ### Pull Request Type - [ ] ✨ feat - [x] 🐛 fix - [ ] ♻️ refactor - [ ] 💄 style - [ ] 🔨 chore - [ ] 📝 docs ### Relevant Issues resolves #4912 ### What is in this change? Handles Prisma unique constraint violation errors (P2002) in the User model to return user-friendly error messages instead of raw Prisma error strings. **Before:** Users see verbose Prisma errors like `Unique constraint failed on the fields: ('username')` **After:** Users see clean messages like `A user with that username already exists` Changes: - Added `Prisma` import from `@prisma/client` in `server/models/user.js` - Added P2002 error handling in `User.create()` method - Added P2002 error handling in `User.update()` method ### Additional Information This fix covers all user creation and update endpoints across the codebase (admin panel, API, invite acceptance, profile updates, etc.) ### Developer Validations - [x] I ran `yarn lint` from the root of the repo & committed changes - [x] Relevant documentation has been updated - [x] I have tested my code functionality - [x] Docker build succeeds locally --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-22 18:36:35 -05:00
yindo closed this issue 2026-02-22 18:36:35 -05:00
yindo changed title from [PR #4914] Fix: Clean username already exists error to [PR #4914] [MERGED] Fix: Clean username already exists error 2026-06-05 15:20:32 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#4816