Skip to content

Wrap tool invocation in Invoke-OAIFunctionCall with try/catch and ret…#105

Merged
dfinke merged 1 commit intomainfrom
try-catch-for-function-call
Oct 23, 2025
Merged

Wrap tool invocation in Invoke-OAIFunctionCall with try/catch and ret…#105
dfinke merged 1 commit intomainfrom
try-catch-for-function-call

Conversation

@dfinke
Copy link
Owner

@dfinke dfinke commented Oct 23, 2025

…urn informative error on failure

@dfinke dfinke requested a review from Copilot October 23, 2025 14:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds error handling to the tool invocation process in Invoke-OAIFunctionCall. When a tool function throws an exception during execution, the error is now caught and returned as an informative message instead of propagating the exception.

Key Changes:

  • Wrapped the tool function invocation in a try/catch block to handle execution errors gracefully
  • Returns a descriptive error message containing the function name, arguments, and error details when invocation fails

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

$result = & $toolFunctionName @toolFunctionArgs
}
catch {
$result = "Error invoking function $($toolFunctionName) with arguments $($toolCall.function.arguments): $_"
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message includes raw arguments from $toolCall.function.arguments which may not be helpful if the arguments were already parsed. Consider using $toolFunctionArgs | ConvertTo-Json -Compress instead to show the actual parsed arguments that were passed to the function.

Suggested change
$result = "Error invoking function $($toolFunctionName) with arguments $($toolCall.function.arguments): $_"
$result = "Error invoking function $($toolFunctionName) with arguments $($toolFunctionArgs | ConvertTo-Json -Compress): $_"

Copilot uses AI. Check for mistakes.
@dfinke dfinke merged commit 73a50c0 into main Oct 23, 2025
3 checks passed
@dfinke dfinke deleted the try-catch-for-function-call branch October 23, 2025 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant