Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Aligning Chroma-specific errors with Generic exceptions returned by FastAPI server #2100

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion chromadb/server/fastapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ async def catch_exceptions_middleware(
return fastapi_json_response(e)
except Exception as e:
logger.exception(e)
return JSONResponse(content={"error": repr(e)}, status_code=500)
return JSONResponse(
content={"error": type(e).__name__, "message": f"{str(e)}"}, status_code=500
)


async def check_http_version_middleware(
Expand Down
6 changes: 4 additions & 2 deletions chromadb/test/property/test_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,11 @@ def test_escape_chars_in_ids(api: ServerAPI) -> None:
def test_delete_empty_fails(api: ServerAPI, kwargs: dict):
api.reset()
coll = api.create_collection(name="foo")
with pytest.raises(Exception) as e:
with pytest.raises(
Exception,
match="You must provide either ids, where, or where_document to delete.",
):
coll.delete(**kwargs)
assert "You must provide either ids, where, or where_document to delete." in str(e)


@pytest.mark.parametrize(
Expand Down
18 changes: 15 additions & 3 deletions clients/js/src/ChromaFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,23 @@ function isOfflineError(error: any): boolean {
);
}

function parseServerError(error: string | undefined): Error {
function parseServerError(
error: string | undefined,
message: string | undefined,
): Error {
const regex = /(\w+)\('(.+)'\)/;
const match = error?.match(regex);
if (error && message) {
switch (error) {
case "ValueError":
return new ChromaValueError(message);
default:
return new ChromaError(error, message);
}
}
if (match) {
const [, name, message] = match;

switch (name) {
case "ValueError":
return new ChromaValueError(message);
Expand Down Expand Up @@ -71,7 +83,7 @@ export const chromaFetch: FetchAPI = async (
`The requested resource could not be found: ${input}`,
);
case 500:
throw parseServerError(respBody?.error);
throw parseServerError(respBody?.error, respBody?.message);
case 502:
case 503:
case 504:
Expand All @@ -85,7 +97,7 @@ export const chromaFetch: FetchAPI = async (
}

if (respBody?.error) {
throw parseServerError(respBody.error);
throw parseServerError(respBody.error, respBody?.message);
}

return resp;
Expand Down
Loading