fix(async): preserve typed errors in research stream mode#168
Open
shuofengzhang wants to merge 1 commit intotavily-ai:masterfrom
Open
fix(async): preserve typed errors in research stream mode#168shuofengzhang wants to merge 1 commit intotavily-ai:masterfrom
shuofengzhang wants to merge 1 commit intotavily-ai:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
AsyncTavilyClientresearch streaming error handling so Tavily-specific exceptions are no longer wrapped into a genericException.UsageLimitExceededErrorForbiddenErrorInvalidAPIKeyErrorBadRequestErrorTimeoutErrorUsageLimitExceededErroron HTTP 429.Insight / Why this matters
In async stream mode,
_research(..., stream=True)raised domain-specific exceptions for non-200 responses, but then immediately caught them with a broadexcept Exceptionand re-raised a generic error.That made stream-mode error handling inconsistent with non-stream mode and with the sync client path. It is easy to miss because happy-path stream tests pass, while typed error handling only appears in failure scenarios.
This change preserves typed exceptions, so callers can implement correct retry/backoff and user messaging logic based on error class instead of brittle string parsing.
Practical gain / Why this matters
Why
Testing
pytest -q tests/test_research.pypytest -qNote
Medium Risk
Changes exception propagation in async streaming mode, which can affect downstream error handling, but is limited in scope and covered by a targeted regression test.
Overview
Async
research(..., stream=True)now preserves Tavily-specific error classes (UsageLimitExceededError,ForbiddenError,InvalidAPIKeyError,BadRequestError,TimeoutError) instead of catching them and rethrowing a genericException; unexpected errors are still wrapped but now use exception chaining (raise ... from e).Adds a regression test ensuring a
429response in streaming mode raisesUsageLimitExceededErrorwith the server-provided message.Reviewed by Cursor Bugbot for commit 9958f47. Bugbot is set up for automated code reviews on this repo. Configure here.