-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(executor): guard against missing content in provider responses #3952
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -124,6 +124,12 @@ export class RouterBlockHandler implements BlockHandler { | |||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const result = await response.json() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (!result.content) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error( | ||||||||||||||||||||||||||||||||||||||||||||||
| 'Provider returned an empty response. The model may be unavailable or the request was malformed.' | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const chosenBlockId = result.content.trim().toLowerCase() | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+127
to
133
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (!result.content) { | |
| throw new Error( | |
| 'Provider returned an empty response. The model may be unavailable or the request was malformed.' | |
| ) | |
| } | |
| const chosenBlockId = result.content.trim().toLowerCase() | |
| if (!result || typeof result !== 'object' || typeof result.content !== 'string') { | |
| throw new Error( | |
| 'Provider returned an empty response. The model may be unavailable or the request was malformed.' | |
| ) | |
| } | |
| const normalizedContent = result.content.trim() | |
| if (normalizedContent.length === 0) { | |
| throw new Error( | |
| 'Provider returned an empty response. The model may be unavailable or the request was malformed.' | |
| ) | |
| } | |
| const chosenBlockId = normalizedContent.toLowerCase() |
Copilot
AI
Apr 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as the legacy path: if (!result.content) doesn’t protect against truthy non-string values, and whitespace-only content will fall through to the JSON parse / fallback and eventually call .trim() anyway. Tighten the validation to require a non-empty trimmed string (and ideally guard result itself) before using result.content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!result.content)won’t catch truthy non-string content, soextractJSONFromResponse(result.content)can still receive a non-string and crash when it calls.trim(). Also, whitespace-only strings slip through and will likely produce a confusing downstream parse/score behavior. Consider validatingtypeof result.content === 'string'andresult.content.trim()before proceeding.