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

[ENH]: Improved error reporting #1817

Merged
merged 2 commits into from
Apr 9, 2024

Conversation

AlabasterAxe
Copy link
Contributor

@AlabasterAxe AlabasterAxe commented Mar 5, 2024

Description of changes

This PR reworks the way error handling works with the JavaScript client. Previously, the api would return objects with error messages under certain circumstances and throw errors in other circumstances. This standardizes that by supplying a custom fetch implementation that translates the http error codes and the server error responses, into a standardized set of errors that are thrown by the client functions.

Test plan

  • Updated javascript tests
  • wrote a new test

Documentation Changes

  • This is a breaking change to the API of the client so this should be documented.

Copy link

github-actions bot commented Mar 5, 2024

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)

init?: RequestInit
): Promise<Response> => {
try {
return await fetch(input, init);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think fetch will not raise if status is 500 no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's a good call. I think we may need to have a larger conversation about what we want our policy to be for these things (although I guess that's my task :) ). Ideally, we'd have a standardized error API at the client level.

e.g.

ChromaConnectionError
ChromaServerError
ChromaUnknownError

@AlabasterAxe AlabasterAxe force-pushed the matt/error-handling branch 2 times, most recently from 298cc78 to c681064 Compare March 6, 2024 18:12
} catch (e) {
expect(e instanceof Error).toBe(true);
expect((e as Error).message).toMatchInlineSnapshot(
`"Failed to connect to chromadb. Make sure your server is running and try again. If you are running from a browser, make sure that your chromadb instance is configured to allow requests from the current origin using the CHROMA_SERVER_CORS_ALLOW_ORIGINS environment variable."`
Copy link
Contributor

Choose a reason for hiding this comment

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

This is super nice!

A frequent problem I see is JS sucks with dual-stack systems where most people will connect to localhost, which maps to :1; however, their server is listening on 127.0.0.1. Can we force JS to try both stacks before giving up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is an interesting question. My gut reaction is that it might cause some surprising behaviors in certain circumstances (e.g. the user has something else running at :1:8000 which causes some cryptic errors).

I think that would be a good conversation to have but I think adding that functionality would be outside of the original scope of this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

@AlabasterAxe, the backend sometimes returns error + message, sometimes just error. Could that break some of the code below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when you say error + message, is that on the response body?

or are you referring to the message field on the error object? that can get thrown by the call to fetch?

@nicolasgere nicolasgere merged commit 1441eae into chroma-core:main Apr 9, 2024
118 checks passed
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.

3 participants