Skip to content

[CHORE] Propogate error messages correctly to user #4235

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

Merged
merged 2 commits into from
Apr 10, 2025

Conversation

jairad26
Copy link
Contributor

@jairad26 jairad26 commented Apr 8, 2025

Description of changes

This PR propogates the error message caught with a modified error message. It fixes this issue
#3688

previous error message:

Traceback (most recent call last):
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/chromadb/api/models/CollectionCommon.py", line 95, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/chromadb/api/models/CollectionCommon.py", line 233, in _validate_and_prepare_add_request
    add_embeddings = self._embed_record_set(record_set=add_records)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/chromadb/api/models/CollectionCommon.py", line 555, in _embed_record_set
    return self._embed(input=record_set[field])  # type: ignore[literal-required]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/chromadb/api/models/CollectionCommon.py", line 568, in _embed
    return self._embedding_function(input=input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/chromadb/api/types.py", line 489, in __call__
    result = call(self, input)
             ^^^^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/chromadb/utils/embedding_functions/openai_embedding_function.py", line 119, in __call__
    response = self.client.embeddings.create(**embedding_params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/.venv/lib/python3.12/site-packages/openai/resources/embeddings.py", line 128, in create
    return self._post(
           ^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1242, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 919, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1023, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: aaask-pr***********************************************************************************************************************************************************gF4A. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/test.py", line 85, in <module>
    coll.add(
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/chromadb/api/models/Collection.py", line 80, in add
    add_request = self._validate_and_prepare_add_request(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/chromadb/api/models/CollectionCommon.py", line 98, in wrapper
    raise type(e)(msg).with_traceback(e.__traceback__)
          ^^^^^^^^^^^^
TypeError: APIStatusError.__init__() missing 2 required keyword-only arguments: 'response' and 'body'

the info is all there but the final output is confusing because of this line
raise type(e)(msg).with_traceback(e.__traceback__)

this line is trying to recreate the error with the new message, but does not track the rest of the arguments in the error. The simplest way to modify the error message is to recreate e.args with the new error message

new error

Traceback (most recent call last):
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/test.py", line 85, in <module>
    coll.add(
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/chromadb/api/models/Collection.py", line 80, in add
    add_request = self._validate_and_prepare_add_request(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/chromadb/api/models/CollectionCommon.py", line 95, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/chromadb/api/models/CollectionCommon.py", line 237, in _validate_and_prepare_add_request
    add_embeddings = self._embed_record_set(record_set=add_records)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/chromadb/api/models/CollectionCommon.py", line 559, in _embed_record_set
    return self._embed(input=record_set[field])  # type: ignore[literal-required]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/chromadb/api/models/CollectionCommon.py", line 572, in _embed
    return self._embedding_function(input=input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/chromadb/api/types.py", line 489, in __call__
    result = call(self, input)
             ^^^^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/chromadb/utils/embedding_functions/openai_embedding_function.py", line 119, in __call__
    response = self.client.embeddings.create(**embedding_params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/.venv/lib/python3.12/site-packages/openai/resources/embeddings.py", line 128, in create
    return self._post(
           ^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1242, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 919, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/Users/jairadhakrishnan/github.com/chroma-core/chroma/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1023, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: aaask-pr***********************************************************************************************************************************************************gF4A. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}} in add.

Test plan

How are these changes tested?

  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs repository?

Copy link

github-actions bot commented Apr 8, 2025

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@jairad26 jairad26 force-pushed the jai/propogate-api-ef-error branch from 1addfda to 2802145 Compare April 9, 2025 21:01
@jairad26 jairad26 force-pushed the jai/remove-sort-page-page-size branch from 2112de5 to e0c61ce Compare April 9, 2025 21:01
@@ -94,8 +94,12 @@ def wrapper(self: Any, *args: Any, **kwargs: Any) -> T:
try:
return func(self, *args, **kwargs)
except Exception as e:
# modify the error message
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this comment doesn't add much value, i can see the msg is modified already

Copy link
Collaborator

@HammadB HammadB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test case for validation before merging that checks the error message, we can use that to make error message expectations documented in code and also harder to change without care.

@jairad26 jairad26 changed the base branch from jai/remove-sort-page-page-size to main April 10, 2025 13:48
@jairad26 jairad26 merged commit 1d8d2b2 into main Apr 10, 2025
133 checks passed
jairad26 added a commit that referenced this pull request Apr 10, 2025
jairad26 added a commit that referenced this pull request Apr 14, 2025
## Description of changes

This PR adds tests for validation_context to ensure the errors raised
match the ones given by the caller, in this case an embedding function.
tests for #4235
## Test plan
*How are these changes tested?*

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants