Skip to content

Commit 76d46b8

Browse files
abnegateclaude
andcommitted
fix: only swallow client-level Collection Exists for shared-table/metadata paths
The code-0 "Collection Exists" from the Mongo client was being converted to DuplicateException in processException, which the local catch in createCollection silently returned true for — bypassing Database::createCollection()'s orphan reconciliation in non-shared mode. Move the handling into createCollection itself where context is available: return true for shared-tables/metadata, throw DuplicateException otherwise so the caller can reconcile. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3760d54 commit 76d46b8

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/Database/Adapter/Mongo.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,16 @@ public function createCollection(string $name, array $attributes = [], array $in
430430
if ($e instanceof DuplicateException) {
431431
return true;
432432
}
433+
// Client throws code-0 "Collection Exists" when its pre-check
434+
// finds the collection. In shared-tables/metadata context this
435+
// is a no-op; otherwise re-throw as DuplicateException so
436+
// Database::createCollection() can run orphan reconciliation.
437+
if ($e->getCode() === 0 && stripos($e->getMessage(), 'Collection Exists') !== false) {
438+
if ($this->getSharedTables() || $name === Database::METADATA) {
439+
return true;
440+
}
441+
throw new DuplicateException('Collection already exists', $e->getCode(), $e);
442+
}
433443
throw $e;
434444
}
435445

@@ -3520,8 +3530,8 @@ protected function processException(\Throwable $e): \Throwable
35203530
return new DuplicateException('Document already exists', $e->getCode(), $e);
35213531
}
35223532

3523-
// Collection already exists (code 48 from MongoDB, code 0 from client pre-check)
3524-
if ($e->getCode() === 48 || ($e->getCode() === 0 && stripos($e->getMessage(), 'Collection Exists') !== false)) {
3533+
// Collection already exists
3534+
if ($e->getCode() === 48) {
35253535
return new DuplicateException('Collection already exists', $e->getCode(), $e);
35263536
}
35273537

0 commit comments

Comments
 (0)