WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#46252 closed enhancement (fixed)

Enhance Error Message for Meta Fields

Reported by: apermo Owned by: TimothyBlynJacobs
Milestone: 5.3 Priority: normal
Severity: minor Version:
Component: REST API Keywords: has-patch needs-testing
Focuses: Cc:

Description

https://core.trac.wordpress.org/browser/trunk/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php#L270

https://core.trac.wordpress.org/browser/trunk/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php#L283

https://core.trac.wordpress.org/browser/trunk/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php#L333

<?php
return new WP_Error(
   'rest_meta_database_error',
   __( 'Could not update meta value in database.' ),
   array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR )
);
?>

These 3 Error messages are actually not helpful, if you submit multiple meta fields, you don't know (at least not on the remote site) which meta was throwing the error.

It would be more helpful/self explaining if the error message was more like:

sprintf( __( 'Could not update the meta value "%s" in database.' ), $meta_key ), 

this way you could directly tell which meta field is throwing the error.

Attachments (2)

46252.diff (1.6 KB) - added by AkSDvP 2 years ago.
46252.2.diff (1.6 KB) - added by AkSDvP 2 years ago.

Download all attachments as: .zip

Change History (9)

#1 @pento
3 years ago

  • Version trunk deleted

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.


2 years ago

#3 @TimothyBlynJacobs
2 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.3
  • Owner set to TimothyBlynJacobs
  • Status changed from new to accepted

I agree this would be a quite helpful improvement.

Considering some of the other metadata improvements planned for 5.3, milestoning for 5.3 as well.

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.


2 years ago

#5 @AkSDvP
2 years ago

With reference to the above conversation, I have created a patch to change exception messages. Please find & review associated patch attached herewith.

@AkSDvP
2 years ago

@AkSDvP
2 years ago

#6 @AkSDvP
2 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

#7 @SergeyBiryukov
2 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 45681:

REST API: Make "Could not update meta value in database" error messages more helpful.

Props apermo, AkSDvP.
Fixes #46252.

Note: See TracTickets for help on using tickets.