fix(utils): embed(texts=[]) crashes with IndexError on empty input#778
Open
devteamaegis wants to merge 1 commit into
Open
fix(utils): embed(texts=[]) crashes with IndexError on empty input#778devteamaegis wants to merge 1 commit into
devteamaegis wants to merge 1 commit into
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's broken
Client.embed(texts=[])(default batching, no images) produces an emptyresponseslist, whichmerge_embed_responsesindexes unconditionally:The crash happens before any network I/O, so an empty input list never gets a meaningful error.
Why it happens
merge_embed_responsesreadsresponses[0]without checking for an empty list.Fix
Guard the empty case and raise a clear
ValueError. The SDK can't synthesise a typed emptyEmbedResponse(it wouldn't knowresponse_type), so an explicit, actionable error is the smallest correct behavior and matches the library's existing input-validation pattern.Test
Added a case asserting
merge_embed_responses([])raisesValueErrorinstead ofIndexError.Fixes #777
Note
Low Risk
Small input-validation guard and test only; no API or embedding merge logic changes for non-empty input.
Overview
Fixes
Client.embed(texts=[])(and any path that merges zero batched responses) so it no longer crashes withIndexErrorwhenmerge_embed_responsesaccessedresponses[0].merge_embed_responsesnow rejects an emptyresponseslist up front with aValueErrorand an explicit message that no texts were provided. A unit test locks in that behavior instead of anIndexError.Reviewed by Cursor Bugbot for commit e7ad74b. Bugbot is set up for automated code reviews on this repo. Configure here.