ai icon indicating copy to clipboard operation
ai copied to clipboard

'InvalidToolArgumentsError' error is thrown to parent scope in streamUi

Open defless opened this issue 2 years ago • 1 comments

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.

Screenshot 2024-07-19 at 15 45 36

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.

defless avatar Jul 19 '24 13:07 defless

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 streamUI tool call triggers the nearest ErrorBoundary but also propagates as an unhandled runtime error.
  • The reporter provides a concrete streamUI reproduction and states that attempts to catch the error in the server action and client side do not work.
  • The screenshot shows InvalidToolArgumentsError surfacing from stream-ui.tsx as an unhandled runtime error.

lgrammel avatar Jul 22 '26 17:07 lgrammel