这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@priethor
Copy link

Fixes #89, making ToolsHandler accept both nested (as seen in handle_tool_call) and unnested error formats.

However, this fix surfaces an inconsistency in error formatting and raises a bigger question: should handle_tool_call, ExecuteAbilityAbility, DiscoverAbilitiesAbility, and GetAbilityInfoAbility use the same format, either nested or not?

Copilot AI review requested due to automatic review settings November 10, 2025 15:38
@github-actions
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: priethor <priethor@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov
Copy link

codecov bot commented Nov 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.75%. Comparing base (48d7ffb) to head (8895697).

Additional details and impacted files
@@             Coverage Diff              @@
##              trunk      #90      +/-   ##
============================================
+ Coverage     79.74%   79.75%   +0.01%     
- Complexity      858      859       +1     
============================================
  Files            46       46              
  Lines          3080     3082       +2     
============================================
+ Hits           2456     2458       +2     
  Misses          624      624              
Flag Coverage Δ
unit 79.75% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

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 enhances error handling in the ToolsHandler by adding support for both string and array error formats. The change provides defensive handling for $result['error'] values, checking if the error is a string before attempting to access it as an array.

Key Changes:

  • Added type checking for $result['error'] to handle both string and array formats
  • Maintains backward compatibility with existing array-based error handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +134 to +138
if ( is_string( $result['error'] ) ) {
$error_message = $result['error'];
} else {
$error_message = $result['error']['message'] ?? 'An error occurred while executing the tool.';
}
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

This change adds handling for $result['error'] as a string, but all error returns in handle_tool_call() and throughout the codebase consistently use array format with ['code' => int, 'message' => string] structure via McpErrorFactory methods.

Could you clarify when $result['error'] would be a string? Based on reviewing:

  • Lines 272, 299, 329, 348: All use McpErrorFactory::*()['error'] which returns arrays
  • Lines 376-379: WP_Error case returns ['message' => ..., 'code' => ...] as an array
  • Lines 409-411: Exception case returns ['message' => ...] as an array

If this is defensive programming for external tool implementations or future scenarios, consider documenting this with a comment explaining when string errors might occur.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

Documented the change in 86cb396

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.

ExecuteAbilityAbility returns incompatible error format with ToolsHandler causing generic error messages

1 participant