ai
ai copied to clipboard
'InvalidToolArgumentsError' error is thrown to parent scope in streamUi
Description
When a zod schema validation error occurs in a streamUI tool-call, the nearest ErrorBoundary is triggered but the error is also thrown to parent scope.
Am I missing something or it just what it's not supposed to do as specified here ?
https://github.com/vercel/ai/blob/68d1f78c8e9ad4ae90693b85fe310d33778cf1f9/packages/core/rsc/stream-ui/stream-ui.tsx#L369-L370
Code example
export async function submitUserMessage (input: string) {
const { tools, openai } = ai();
const aiState = getMutableAIState();
aiState.update([
...aiState.get(),
{ role: 'user', content: input, id: generateId() },
]);
const ui = await streamUI({
model: openai('gpt-3.5-turbo'),
system: ``,
messages: [...aiState.get()],
tools: tools(aiState),
toolChoice: 'required',
});
return {
id: generateId(),
display: (
<ErrorBoundary fallback="error">
{ ui.value }
</ErrorBoundary>),
)
};
}
Additional context
I tried to catch this error at different levels (server action & client side), but its not working.
Identify issue type
Identified as Bug
Confidence: High
Rationale
This describes concrete error-propagation behavior in the existing streamUI API that appears inconsistent with its intended handling, rather than requesting a new capability.
Evidence
- A Zod validation failure during a
streamUItool call triggers the nearest ErrorBoundary but also propagates as an unhandled runtime error. - The reporter provides a concrete
streamUIreproduction and states that attempts to catch the error in the server action and client side do not work. - The screenshot shows
InvalidToolArgumentsErrorsurfacing fromstream-ui.tsxas an unhandled runtime error.