From 00e9323b273f2d973cd52d63cb19b5f3e4364e42 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 22 Jul 2026 12:30:48 +0800 Subject: [PATCH] fix: map duplicate-folder 400 to CollectionAlreadyExistsError in cloud create_collection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- pageindex/backend/cloud.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pageindex/backend/cloud.py b/pageindex/backend/cloud.py index c44e892..44ca151 100644 --- a/pageindex/backend/cloud.py +++ b/pageindex/backend/cloud.py @@ -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