Skip to content

Commit f845903

Browse files
committed
fix(cli): Replace InvalidCollectionException with NotFoundError
1 parent d6772ad commit f845903

File tree

6 files changed

+12
-15
lines changed

6 files changed

+12
-15
lines changed

src/vectorcode/mcp_main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from chromadb.api import AsyncClientAPI
88
from chromadb.api.models.AsyncCollection import AsyncCollection
9-
from chromadb.errors import InvalidCollectionException
9+
from chromadb.errors import NotFoundError
1010

1111
try: # pragma: nocover
1212
from mcp import ErrorData, McpError
@@ -116,7 +116,7 @@ async def mcp_server():
116116
default_client = await get_client(default_config)
117117
try:
118118
default_collection = await get_collection(default_client, default_config)
119-
except InvalidCollectionException:
119+
except NotFoundError:
120120
default_collection = None
121121

122122
mcp.add_tool(

src/vectorcode/subcommands/drop.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from chromadb.errors import InvalidCollectionException
1+
from chromadb.errors import NotFoundError
22

33
from vectorcode.cli_utils import Config
44
from vectorcode.common import get_client, get_collection
@@ -12,6 +12,6 @@ async def drop(config: Config) -> int:
1212
await client.delete_collection(collection.name)
1313
print(f"Collection for {collection_path} has been deleted.")
1414
return 0
15-
except (ValueError, InvalidCollectionException):
15+
except (ValueError, NotFoundError):
1616
print(f"There's no existing collection for {config.project_root}")
1717
return 1

src/vectorcode/subcommands/query/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from chromadb import GetResult
66
from chromadb.api.models.AsyncCollection import AsyncCollection
77
from chromadb.api.types import IncludeEnum
8-
from chromadb.errors import InvalidCollectionException, InvalidDimensionException
8+
from chromadb.errors import InvalidDimensionException, NotFoundError
99

1010
from vectorcode.chunking import StringChunker
1111
from vectorcode.cli_utils import Config, QueryInclude, expand_globs, expand_path
@@ -151,7 +151,7 @@ async def query(configs: Config) -> int:
151151
collection = await get_collection(client, configs, False)
152152
if not verify_ef(collection, configs):
153153
return 1
154-
except (ValueError, InvalidCollectionException):
154+
except (ValueError, NotFoundError):
155155
print(
156156
f"There's no existing collection for {configs.project_root}",
157157
file=sys.stderr,

src/vectorcode/subcommands/update.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import tqdm
77
from chromadb.api.types import IncludeEnum
8-
from chromadb.errors import InvalidCollectionException
8+
from chromadb.errors import NotFoundError
99

1010
from vectorcode.cli_utils import Config
1111
from vectorcode.common import get_client, get_collection, verify_ef
@@ -19,7 +19,7 @@ async def update(configs: Config) -> int:
1919
except IndexError:
2020
print("Failed to get/create the collection. Please check your config.")
2121
return 1
22-
except (ValueError, InvalidCollectionException):
22+
except (ValueError, NotFoundError):
2323
print(
2424
f"There's no existing collection for {configs.project_root}",
2525
file=sys.stderr,

tests/subcommands/query/test_query.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from chromadb import GetResult
55
from chromadb.api.models.AsyncCollection import AsyncCollection
66
from chromadb.api.types import IncludeEnum
7-
from chromadb.errors import InvalidCollectionException, InvalidDimensionException
7+
from chromadb.errors import InvalidDimensionException, NotFoundError
88

99
from vectorcode.cli_utils import CliAction, Config, QueryInclude
1010
from vectorcode.subcommands.query import (
@@ -456,10 +456,7 @@ async def test_query_invalid_collection():
456456
patch("vectorcode.subcommands.query.get_collection") as mock_get_collection,
457457
patch("sys.stderr"),
458458
):
459-
# Make get_collection raise InvalidCollectionException
460-
mock_get_collection.side_effect = InvalidCollectionException(
461-
"Invalid collection"
462-
)
459+
mock_get_collection.side_effect = NotFoundError("Invalid collection")
463460

464461
# Call the function
465462
result = await query(config)

tests/subcommands/test_update.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44
from chromadb.api.types import IncludeEnum
5-
from chromadb.errors import InvalidCollectionException
5+
from chromadb.errors import NotFoundError
66

77
from vectorcode.cli_utils import Config
88
from vectorcode.subcommands.update import update
@@ -113,7 +113,7 @@ async def test_update_invalid_collection_exception():
113113
patch("vectorcode.subcommands.update.get_client", return_value=mock_client),
114114
patch(
115115
"vectorcode.subcommands.update.get_collection",
116-
side_effect=InvalidCollectionException,
116+
side_effect=NotFoundError,
117117
),
118118
patch("sys.stderr"),
119119
):

0 commit comments

Comments
 (0)