-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: Add information about, db collection and index name on duplicate value error #9919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: alpha
Are you sure you want to change the base?
feat: Add information about, db collection and index name on duplicate value error #9919
Conversation
|
I will reformat the title to use the proper commit message syntax. |
|
🚀 Thanks for opening this pull request! |
📝 WalkthroughWalkthroughA helper was added to parse MongoDB E11000 duplicate key errors for database/collection/index names; its output is appended to Parse.Error messages at three duplicate-value error sites. Tests were updated to assert the formatted error message. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant ParseServer
participant MongoDB
rect rgba(0,128,0,0.06)
Client->>ParseServer: create/update object with unique-conflicting value
ParseServer->>MongoDB: write/findOneAndUpdate request
MongoDB-->>ParseServer: E11000 duplicate key error (raw message)
ParseServer->>ParseServer: mongoUniqueIndexErrorFormatter(parse raw message)
ParseServer-->>Client: Parse.Error(DUPLICATE_VALUE + formatted "collection:index" info)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/Adapters/Storage/Mongo/MongoStorageAdapter.js (1)
744-753: Apply formatter consistently inensureUniqueness.The DUPLICATE_VALUE error thrown in this method doesn't use
mongoUniqueIndexErrorFormatter, creating inconsistent error messages across the codebase. Users would see different error formats depending on which code path triggers the duplicate key violation.Apply this diff for consistency:
.catch(error => { if (error.code === 11000) { throw new Parse.Error( Parse.Error.DUPLICATE_VALUE, - 'Tried to ensure field uniqueness for a class that already has duplicates.' + `Tried to ensure field uniqueness for a class that already has duplicates.${mongoUniqueIndexErrorFormatter(error.message)}` ); } throw error; })
🧹 Nitpick comments (1)
spec/schemas.spec.js (1)
3811-3841: Consider more flexible error message assertion.The test uses an exact string match with hardcoded database and collection names. This makes the test brittle—it will break if test configuration changes (database name, collection prefix) even though the functionality works correctly.
Consider using a pattern-based assertion instead:
- expect(error.message).toEqual('A duplicate value for a field with unique values was provided. Duplicate index: code_1 on collection test_UniqueIndexClass in db parseServerMongoAdapterTestDatabase') + expect(error.message).toMatch(/A duplicate value for a field with unique values was provided\. Duplicate index: code_1 on collection \w+UniqueIndexClass in db \w+/);Alternatively, verify the presence of key components:
- expect(error.message).toEqual('A duplicate value for a field with unique values was provided. Duplicate index: code_1 on collection test_UniqueIndexClass in db parseServerMongoAdapterTestDatabase') + expect(error.message).toContain('A duplicate value for a field with unique values was provided'); + expect(error.message).toContain('Duplicate index: code_1'); + expect(error.message).toContain('UniqueIndexClass');
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
spec/schemas.spec.js(1 hunks)src/Adapters/Storage/Mongo/MongoStorageAdapter.js(3 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-11-08T13:46:04.917Z
Learning: When reviewing Parse Server PRs that add new features, always check whether the feature is documented in the README.md file, though for new Parse Server options this is optional rather than required.
📚 Learning: 2025-05-09T09:59:06.289Z
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: Tests in the parse-server repository should use promise-based approaches rather than callback patterns with `done()`. Use a pattern where a Promise is created that resolves when the event occurs, then await that promise.
Applied to files:
spec/schemas.spec.js
📚 Learning: 2025-05-09T09:59:06.289Z
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`. The preferred pattern is to create a Promise that resolves when an expected event occurs, then await that Promise.
Applied to files:
spec/schemas.spec.js
📚 Learning: 2025-05-04T20:41:05.147Z
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 9445
File: spec/ParseLiveQuery.spec.js:1312-1338
Timestamp: 2025-05-04T20:41:05.147Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`.
Applied to files:
spec/schemas.spec.js
📚 Learning: 2025-10-16T19:27:05.311Z
Learnt from: Moumouls
Repo: parse-community/parse-server PR: 9883
File: spec/CloudCodeLogger.spec.js:410-412
Timestamp: 2025-10-16T19:27:05.311Z
Learning: In spec/CloudCodeLogger.spec.js, the test "should log cloud function triggers using the silent log level" (around lines 383-420) is known to be flaky and requires the extra `await new Promise(resolve => setTimeout(resolve, 100))` timeout after awaiting `afterSavePromise` for reliability, even though it may appear redundant.
Applied to files:
spec/schemas.spec.js
🔇 Additional comments (2)
src/Adapters/Storage/Mongo/MongoStorageAdapter.js (2)
511-529: LGTM! Error message augmentation improves debuggability.The duplicate value error now includes parsed collection and index information, which directly addresses the PR objective of making duplicate key errors easier to debug.
597-607: LGTM! Consistent error message enhancement.The formatter is correctly applied here, maintaining consistency with the
createObjectmethod.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## alpha #9919 +/- ##
==========================================
+ Coverage 93.00% 93.07% +0.07%
==========================================
Files 187 187
Lines 15105 15233 +128
Branches 174 177 +3
==========================================
+ Hits 14048 14178 +130
+ Misses 1045 1043 -2
Partials 12 12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Rahul Lanjewar <63550998+RahulLanjewar93@users.noreply.github.com>
Pull Request
Issue
Closes: #9891
Approach
Tasks
Summary by CodeRabbit
Bug Fixes
Tests