Skip to content

Conversation

@gziolo
Copy link
Member

@gziolo gziolo commented Aug 19, 2025

It addresses the following refactoring:

Consider updating WP_Ability to return WP_Error for better error handling which would then simplify and unify the implementation in REST API controller.

This PR standardizes error handling in the REST API abilities run controller by introducing consistent error codes for different types of validation failures and moving validation logic from the REST controller into the core WP_Ability class.

Testing

Run npm run test:php and make sure all tests pass.

@gziolo gziolo self-assigned this Aug 19, 2025
@gziolo gziolo added [Status] In Progress Assigned work scheduled [Type] Enhancement New feature or request labels Aug 19, 2025
@gziolo gziolo requested a review from Copilot August 20, 2025 06:17
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 standardizes error handling in the REST API abilities run controller by introducing consistent error codes for different types of validation failures and moving validation logic from the REST controller into the core WP_Ability class.

  • Replaced generic REST error codes with specific ability-related error codes for better error identification
  • Moved input/output validation from REST controller to WP_Ability class to centralize validation logic
  • Updated permission handling to properly propagate input validation errors

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
includes/rest-api/endpoints/class-wp-rest-abilities-run-controller.php Removed duplicate validation methods and updated error codes for method and permission checks
includes/abilities-api/class-wp-ability.php Enhanced validation methods to return standardized WP_Error objects and improved error propagation in execute method
tests/unit/rest-api/wpRestAbilitiesRunController.php Updated test assertions to expect new standardized error codes
tests/unit/abilities-api/wpRegisterAbility.php Updated test assertions and removed expected incorrect usage warnings

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

@gziolo gziolo marked this pull request as ready for review August 20, 2025 07:33
Copy link
Contributor

@justlevine justlevine left a comment

Choose a reason for hiding this comment

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

Code lgtm and tests passing locally too 🚀

(I know you marked this in-progress, but it looks complete to me 😇)

@gziolo gziolo removed the [Status] In Progress Assigned work scheduled label Aug 20, 2025
@gziolo
Copy link
Member Author

gziolo commented Aug 20, 2025

I forgot to remove in progress status 😄

Yes, it should be ready to land.

@gziolo gziolo merged commit 2da7f46 into trunk Aug 21, 2025
30 checks passed
@gziolo gziolo deleted the update/rest-api-execute-wp-error branch August 21, 2025 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend error handling for ability schema validation

3 participants