Skip to content

Commit c43021f

Browse files
committed
fix: add null/non-object guards to textPartCount filter in empty output error path
The filter callback for textPartCount directly accessed part.type and part.text without checking if part is a valid object first. If responseParts contains null/undefined entries, getOpenCodeTextResponse safely skips them (returning empty string), triggering the empty-output branch, but the unguarded filter would throw a TypeError before the error could be properly tagged and handled. Add the same guards used in getOpenCodeTextResponse: check for truthy, object type, and property existence before accessing values.
1 parent 6dafd93 commit c43021f

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

apps/server/src/textGeneration/OpenCodeTextGeneration.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,13 @@ export const makeOpenCodeTextGeneration = Effect.fn("makeOpenCodeTextGeneration"
442442
...promptContext,
443443
responsePartCount: responseParts.length,
444444
textPartCount: responseParts.filter(
445-
(part) => part.type === "text" && typeof part.text === "string",
445+
(part) =>
446+
!!part &&
447+
typeof part === "object" &&
448+
"type" in part &&
449+
part.type === "text" &&
450+
"text" in part &&
451+
typeof part.text === "string",
446452
).length,
447453
});
448454
}

0 commit comments

Comments
 (0)