Skip to content

Conversation

@RahulLanjewar93
Copy link
Contributor

@RahulLanjewar93 RahulLanjewar93 commented Nov 8, 2025

Pull Request

Issue

Closes: #9891

Approach

Tasks

  • Add tests
  • Add changes to documentation (guides, repository pages, code comments)
  • Add security check
  • Add new Parse Error codes to Parse JS SDK

Summary by CodeRabbit

  • Bug Fixes

    • Duplicate-value error messages now include database, collection, and index names across create/update operations, giving clearer context for unique-constraint failures.
  • Tests

    • Added test coverage that asserts the exact duplicate-value error message to ensure accurate, consistent reporting.

@parse-github-assistant
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title feat: add information about, db collection and index name on duplicate value error feat: Add information about, db collection and index name on duplicate value error Nov 8, 2025
@parse-github-assistant
Copy link

🚀 Thanks for opening this pull request!

@coderabbitai
Copy link

coderabbitai bot commented Nov 8, 2025

📝 Walkthrough

Walkthrough

A 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

Cohort / File(s) Summary
Mongo storage adapter (error formatting)
src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Adds mongoUniqueIndexErrorFormatter that parses Mongo duplicate key messages (E11000) to extract database, collection, and index names. Appends the formatted index/collection info to duplicate-value Parse.Errors in create, findOneAndUpdate, and createObject flows.
Test update
spec/schemas.spec.js
Adds an assertion verifying the duplicate-value error message includes the formatted collection/index information.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Focus areas:
    • Verify the regex covers common Mongo E11000 message formats (including Mongo versions / Atlas variations).
    • Confirm the formatter gracefully handles parsing failures (returns empty string) without leaking sensitive details.
    • Ensure all three insertion points consistently append the formatted info and maintain existing error codes/flow.
    • Review the updated test for robustness against variations in error message formatting.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding database collection and index name information to duplicate value error messages.
Description check ✅ Passed The PR description follows the template structure with the required Issue section completed (closes #9891) and tests marked as added, though the Approach section lacks implementation details.
Linked Issues check ✅ Passed The code changes fully satisfy issue #9891 requirements: a helper function extracts database, collection, and index names from MongoDB errors, and error messages are augmented in create and update operations.
Out of Scope Changes check ✅ Passed All changes are directly scoped to addressing the linked issue: the helper function and error message augmentations focus only on extracting and displaying duplicate index information.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 17c8909 and 0473c90.

📒 Files selected for processing (1)
  • src/Adapters/Storage/Mongo/MongoStorageAdapter.js (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Adapters/Storage/Mongo/MongoStorageAdapter.js
⏰ 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)
  • GitHub Check: PostgreSQL 15, PostGIS 3.5
  • GitHub Check: PostgreSQL 16, PostGIS 3.5
  • GitHub Check: PostgreSQL 17, PostGIS 3.5
  • GitHub Check: PostgreSQL 15, PostGIS 3.4
  • GitHub Check: PostgreSQL 15, PostGIS 3.3
  • GitHub Check: Check Definitions
  • GitHub Check: Docker Build
  • GitHub Check: Code Analysis (javascript)

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@parseplatformorg
Copy link
Contributor

parseplatformorg commented Nov 8, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link

@coderabbitai coderabbitai bot left a 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 in ensureUniqueness.

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

📥 Commits

Reviewing files that changed from the base of the PR and between a85ba19 and 17c8909.

📒 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 createObject method.

@codecov
Copy link

codecov bot commented Nov 8, 2025

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.07%. Comparing base (1b23475) to head (0473c90).
⚠️ Report is 51 commits behind head on alpha.

Files with missing lines Patch % Lines
src/Adapters/Storage/Mongo/MongoStorageAdapter.js 90.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: Rahul Lanjewar <63550998+RahulLanjewar93@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Collection and index name not visible when duplicate value for a unique field is encountered

2 participants