fix: map duplicate-folder 400 to CollectionAlreadyExistsError in cloud create_collection

The server rejects a duplicate folder name with HTTP 400 ('A folder named
"x" already exists in this location'); the local backend raises
CollectionAlreadyExistsError for the same condition (4e6a135 wired the new
exception into sqlite only). except CollectionAlreadyExistsError written
against local mode never fired on cloud, where the 400 surfaced as a bare
CloudAPIError — the same parity gap _doc_request already closes for 404 →
DocumentNotFoundError.
This commit is contained in:
Ray 2026-07-22 12:30:48 +08:00
parent 225dcc31b4
commit 00e9323b27

View file

@ -13,8 +13,9 @@ import requests
from typing import Any, AsyncIterator, Callable
from ..cloud_api import API_BASE # single source of truth for the cloud base URL
from ..errors import (AUTH_HINT, CloudAPIError, CollectionNotFoundError,
DocumentNotFoundError, PageIndexError)
from ..errors import (AUTH_HINT, CloudAPIError, CollectionAlreadyExistsError,
CollectionNotFoundError, DocumentNotFoundError,
PageIndexError)
from ..events import QueryEvent
logger = logging.getLogger(__name__)
@ -142,6 +143,11 @@ class CloudBackend:
if e.status_code in self._FOLDER_UNAVAILABLE:
self._warn_folder_upgrade()
self._folder_id_cache[name] = None
elif e.status_code == 400 and "already exists" in str(e):
# Duplicate-name 400, for parity with the local backend's
# error taxonomy.
raise CollectionAlreadyExistsError(
f"Collection '{name}' already exists") from e
else:
raise