{"record":{"id":"0c876ee261732908","repo":"vercel/ai","slug":"error-message-0c876e","errorCode":null,"errorMessage":"error.message","messagePattern":"error\\.message","errorType":"exception","errorClass":"RunError","httpStatus":null,"severity":"error","filePath":"packages/code-mode/src/run-code-mode.ts","lineNumber":333,"sourceCode":"      toolName,\n      inputJson,\n      tools: input.tools,\n      baseExecutionOptions,\n      codeModeOptions: input.options ?? {},\n      maxToolInputBytes: policy.maxToolInputBytes,\n      maxToolOutputBytes: policy.maxToolOutputBytes,\n      toolCallId,\n      ...(codeModeInterrupt === undefined ? {} : { codeModeInterrupt }),\n      skipApproval,\n    });\n    if (outcome.type === 'interrupted') {\n      return context.interrupt(outcome.payload);\n    }\n    return fromJsonPayload(outcome.valueJson);\n  } catch (error) {\n    if (error instanceof CodeModeError) {\n      codeModeErrors.push(error);\n      throw new RunError(error.message, error.code, error.details);\n    }\n    if (\n      RunError.isInstance(error) ||\n      (error instanceof Error && error.name === 'HostFunctionInterruptSignal')\n    ) {\n      throw error;\n    }\n    throw new RunError('Host tool failed.', 'CODE_MODE_HOST_TOOL_ERROR');\n  }\n}\n\nfunction assertInterruptPayload(value: unknown): CodeModeInterruptPayload {\n  if (\n    typeof value !== 'object' ||\n    value === null ||\n    Array.isArray(value) ||\n    typeof (value as { kind?: unknown }).kind !== 'string'\n  ) {","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/code-mode/src/run-code-mode.ts#L315-L351","documentation":"In invokeCodeModeTool's catch block, errors that are already CodeModeError instances (e.g. protocol, size-limit, or timeout errors raised during tool invocation) are recorded and rethrown as a RunError carrying error.message (the message shown in this entry is a template placeholder — the actual message is the original CodeModeError's message). This preserves the specific code-mode error message and code across the sandbox host-function boundary so it can later be restored via findPreservedCodeModeError.","triggerScenarios":"Any nested CodeModeError thrown while invoking a host tool from sandbox code — e.g. tool input exceeding maxToolInputBytes, protocol errors in the interrupt machinery, or serialization failures — propagates out as a RunError with the original message.","commonSituations":"Passing oversized or non-serializable arguments to tools from generated code; hitting tool input/output byte limits configured in executionPolicy.","solutions":["Read the RunError's message and code (e.g. CODE_MODE_TOOL_INPUT_TOO_LARGE) to identify the underlying limit or protocol violation.","Shrink or restructure tool inputs in the sandbox code to fit maxToolInputBytes.","Catch CodeModeError.isInstance around runCodeMode calls to access code and details for structured handling."],"exampleFix":"// before\nawait runCodeMode({ js, tools }); // opaque failure\n// after\ntry {\n  await runCodeMode({ js, tools });\n} catch (error) {\n  if (CodeModeError.isInstance(error)) console.error(error.code, error.details);\n  throw error;\n}","handlingStrategy":"try-catch","validationCode":"// Validate tool inputs in sandbox code before calling tools:\nconst inputJson = JSON.stringify(toolInput);\nif (inputJson.length > maxToolInputBytes) throw new Error('tool input too large');","typeGuard":null,"tryCatchPattern":"try {\n  await runCodeMode({ js, tools });\n} catch (error) {\n  if (CodeModeError.isInstance(error)) {\n    console.error(`code-mode failed: ${error.message}`, error.code, error.details);\n  }\n  throw error;\n}","preventionTips":["Keep tool inputs small and JSON-serializable.","Inspect RunError code fields (CODE_MODE_*) to pinpoint which limit was hit.","Log error.details which carries structured context like interruptId."],"tags":["code-mode","run-error","error-wrapping","sandbox"],"backgroundTag":"sandbox-host-error-wrapping","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}