Index: src/wp-includes/comment.php
===================================================================
--- src/wp-includes/comment.php	(revision 39166)
+++ src/wp-includes/comment.php	(working copy)
@@ -2119,48 +2119,50 @@ function wp_set_comment_status($comment_
 	do_action( 'wp_set_comment_status', $comment->comment_ID, $comment_status );
 
 	wp_transition_comment_status($comment_status, $comment_old->comment_approved, $comment);
 
 	wp_update_comment_count($comment->comment_post_ID);
 
 	return true;
 }
 
 /**
  * Updates an existing comment in the database.
  *
  * Filters the comment and makes sure certain fields are valid before updating.
  *
  * @since 2.0.0
+ * @since 4.x.0 The $wp_error parameter was added.
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
  * @param array $commentarr Contains information on the comment.
- * @return int Comment was updated if value is 1, or was not updated if value is 0.
+ * @param bool  $wp_error Optional. Whether to return a WP_Error on failure. Default false.
+ * @return int|bool|WP_Error Number of comment rows updated on success (0 or 1). The value false or WP_Error on failure.
  */
-function wp_update_comment($commentarr) {
+function wp_update_comment( $commentarr, $wp_error = false ) {
 	global $wpdb;
 
 	// First, get all of the original fields
 	$comment = get_comment($commentarr['comment_ID'], ARRAY_A);
 	if ( empty( $comment ) ) {
-		return 0;
+		return $wp_error ? new WP_Error( 'invalid_comment_id', __( 'Invalid comment ID.' ) ) : false;
 	}
 
 	// Make sure that the comment post ID is valid (if specified).
 	if ( ! empty( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) {
-		return 0;
+		return $wp_error ? new WP_Error( 'invalid_post_id', __( 'Invalid post ID.' ) ) : false;
 	}
 
 	// Escape data pulled from DB.
 	$comment = wp_slash($comment);
 
 	$old_status = $comment['comment_approved'];
 
 	// Merge old and new fields with new fields overwriting old ones.
 	$commentarr = array_merge($comment, $commentarr);
 
 	$commentarr = wp_filter_comment( $commentarr );
 
 	// Now extract the merged array.
 	$data = wp_unslash( $commentarr );
 
@@ -2190,30 +2192,33 @@ function wp_update_comment($commentarr) 
 
 	/**
 	 * Filters the comment data immediately before it is updated in the database.
 	 *
 	 * Note: data being passed to the filter is already unslashed.
 	 *
 	 * @since 4.7.0
 	 *
 	 * @param array $data       The new, processed comment data.
 	 * @param array $comment    The old, unslashed comment data.
 	 * @param array $commentarr The new, raw comment data.
 	 */
 	$data = apply_filters( 'wp_update_comment_data', $data, $comment, $commentarr );
 
 	$rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) );
+	if ( false === $rval ) {
+		return $wp_error ? new WP_Error( 'db_update_error', __('Could not update comment in the database'), $wpdb->last_error ) : false;
+	}
 
 	clean_comment_cache( $comment_ID );
 	wp_update_comment_count( $comment_post_ID );
 	/**
 	 * Fires immediately after a comment is updated in the database.
 	 *
 	 * The hook also fires immediately before comment status transition hooks are fired.
 	 *
 	 * @since 1.2.0
 	 * @since 4.6.0 Added the `$data` parameter.
 	 *
 	 * @param int   $comment_ID The comment ID.
 	 * @param array $data       Comment data.
 	 */
 	do_action( 'edit_comment', $comment_ID, $data );
