googleapis / googleapis/nodejs-agentplatform
triggerUncaughtException is thrown because errors occur in both streams after `responseStream.tee()` in `processStream`
- Dominant language
- TypeScript
- Stars
- 182
- Forks
- 69
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 10
Description
https://github.com/googleapis/nodejs-vertexai/blob/main/src/functions/post_fetch_processing.ts#L92-L96
In the `processStream` function, the use of `responseStream.tee()` at the end creates a situation where if errors occur in both the original `responseStream` and the teed stream, the caller needs to handle the `catch` for both streams to avoid triggerUncaughtException.
```ts
const result = await vertexAI.getGenerativeModel({ model })
.generateContentStream({ contents });
// To avoid triggerUncaughtException
result.response.catch(err => {});
return ReadableStream.from(result.stream).pipeThrough(
createCustomResponseTransform(),
); // Errors in result.stream are finally caught outside of this process.
```
Contributor guide
Assessment
This issue has not been assessed yet.