From 50d20faf9a5f6f8534ac6ddfcdc10b15e4004a5e Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 16 Oct 2024 06:45:43 -0700 Subject: [PATCH] Return a proper `WP_Error` object when failing to update a comment (#514) --- features/comment.feature | 10 ++++++++++ src/Comment_Command.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/features/comment.feature b/features/comment.feature index e5746ebb..290954e0 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -70,6 +70,16 @@ Feature: Manage WordPress comments """ And the return code should be 1 + Scenario: Updating an invalid comment should return an error + Given a WP install + + When I try `wp comment update 22 --comment_author=Foo` + Then the return code should be 1 + And STDERR should contain: + """ + Warning: Could not update comment. + """ + Scenario: Get details about an existing comment When I run `wp comment get 1` Then STDOUT should be a table containing rows: diff --git a/src/Comment_Command.php b/src/Comment_Command.php index 1ff6b361..0661ba91 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -118,7 +118,7 @@ public function update( $args, $assoc_args ) { $assoc_args, function ( $params ) { if ( ! wp_update_comment( $params ) ) { - return new WP_Error( 'Could not update comment.' ); + return new WP_Error( 'db_error', 'Could not update comment.' ); } return true;