From f5aacf1166721ecec32af7b0cee2b3e107e48f40 Mon Sep 17 00:00:00 2001 From: dfinke Date: Thu, 23 Oct 2025 10:18:01 -0400 Subject: [PATCH] Wrap tool invocation in Invoke-OAIFunctionCall with try/catch and return informative error on failure --- Public/Invoke-OAIFunctionCall.ps1 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Public/Invoke-OAIFunctionCall.ps1 b/Public/Invoke-OAIFunctionCall.ps1 index 0e1f169..99233bb 100644 --- a/Public/Invoke-OAIFunctionCall.ps1 +++ b/Public/Invoke-OAIFunctionCall.ps1 @@ -26,7 +26,12 @@ function Invoke-OAIFunctionCall { Write-Verbose "$toolFunctionName $($toolFunctionArgs | ConvertTo-Json -Compress)" if (Get-Command $toolFunctionName -ErrorAction SilentlyContinue) { - $result = & $toolFunctionName @toolFunctionArgs + try { + $result = & $toolFunctionName @toolFunctionArgs + } + catch { + $result = "Error invoking function $($toolFunctionName) with arguments $($toolCall.function.arguments): $_" + } } else { $result = "Function $toolFunctionName not found"