Skip to content

fix: use error code 48 for collection exists exception#33

Merged
abnegate merged 1 commit intomainfrom
fix-collection-exists-code
Mar 13, 2026
Merged

fix: use error code 48 for collection exists exception#33
abnegate merged 1 commit intomainfrom
fix-collection-exists-code

Conversation

@abnegate
Copy link
Member

@abnegate abnegate commented Mar 13, 2026

Summary

  • The createCollection method in Client.php throws an Exception with code 0 when a collection already exists
  • The database adapter's processException checks for code 48 (MongoDB NamespaceExists) to convert to DuplicateException, which is then handled gracefully by returning true
  • Without the correct error code, the exception propagates as a 500 server error, breaking shared tables mode where collections like _audit are shared across projects

Test plan

  • Verify MongoDB shared_v1 and shared_v2 modes can create projects without 500 errors
  • Verify createCollection for an existing collection returns true instead of throwing

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling and reporting when attempting to create a collection that already exists with enhanced diagnostic information.

The createCollection method threw Exception with code 0 when a
collection already exists. The database adapter's processException
checks for code 48 (MongoDB NamespaceExists) to convert to
DuplicateException, which is then handled gracefully. Without the
correct code, the exception propagates as a server error.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 728fa91e-db0b-476c-85b6-10d15299892a

📥 Commits

Reviewing files that changed from the base of the PR and between 45bedf3 and bf85c7f.

📒 Files selected for processing (1)
  • src/Client.php

📝 Walkthrough

Walkthrough

The createCollection method in src/Client.php now includes an exception code (48) when throwing an exception for an already-existing collection. Additionally, composer.json was modified. Both are minimal, focused changes.

Changes

Cohort / File(s) Summary
Exception Code Addition
src/Client.php
Updated createCollection method to include error code 48 when throwing an exception for duplicate collections.
Dependency Configuration
composer.json
Minor version or dependency adjustment; lines updated.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A code of forty-eight now rings,
When collections attempt to take wing,
Already here, we kindly convey,
With an error code leading the way! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: use error code 48 for collection exists exception' directly describes the main change: updating the error code to 48 for collection existence exceptions.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-collection-exists-code
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@abnegate abnegate merged commit 83dbcde into main Mar 13, 2026
4 checks passed
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.

1 participant