fix(module): surface tool errors as throwable exceptions in sandbox#208
Open
Mat4m0 wants to merge 1 commit intonuxt-modules:mainfrom
Open
fix(module): surface tool errors as throwable exceptions in sandbox#208Mat4m0 wants to merge 1 commit intonuxt-modules:mainfrom
Mat4m0 wants to merge 1 commit intonuxt-modules:mainfrom
Conversation
Tool errors (isError: true) were returned as plain strings, making them indistinguishable from successful results in sandbox code. try/catch never fires, and structured error details from structuredContent are lost. Return a __toolError sentinel from dispatch so the sandbox proxy can throw a structured Error with .tool, .isToolError, and .details fields.
Contributor
|
@Mat4m0 is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Thank you for following the naming conventions! 🙏 |
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
Tool errors are opaque and uncatchable in code mode
When a tool returns
isError: true, the dispatch function returns the error text as a regular value. The sandbox code has no way to distinguish an error from a successful string result, andtry/catchnever fires. Structured error details fromstructuredContentare also lost.Root cause
buildDispatchFunctions()passedisErrorresults through the same text extraction path as successes, losing the error signal.Solution
Dispatch side (
index.ts): Whenresult.isErroris true, return a{ __toolError, message, tool, details }sentinel object instead of extracting text.detailscarriesresult.structuredContentwhen available.Sandbox side (
executor.ts): Therpc()proxy detects the__toolErrorsentinel and throws a structuredErrorwith.tool,.isToolError, and.detailsproperties — making tool errors catchable withtry/catch.Files changed
index.tsbuildDispatchFunctions(): checkisError→ return__toolErrorsentinel withdetails; export for testingexecutor.tsrpc()proxy: detect__toolError, throw structuredErrorcodemode.test.tsTest coverage
5 new tests in
test/codemode.test.ts:__toolErrorsentinel forisErrorresultsstructuredContentincluded asdetailsin error sentineldetailswhen nostructuredContentisError+structuredContentprioritizes error over structured dataAll 150 tests pass (20 test files).
Test plan
pnpm testpasses (150/150)pnpm lintpassestsc --noEmitpassesisError: true→ sandbox throws structuredErrorwith.tool,.isToolError,.detailsisError: true+structuredContent→ error sentinel includes detailsAI tools used