Ticket #4809 (closed defect: fixed)

Opened 11 months ago

Last modified 5 months ago

Returning WP_Error objects in unexpected places

Reported by: filosofo Assigned to: filosofo
Priority: high Milestone: 2.5
Component: General Version: 2.3
Severity: major Keywords: wp_error
Cc: filosofo

Description

All of the functions listed below return WP_Error objects if something goes wrong. The problem is that in most of the many places where these functions appear throughout the WordPress codebase, whatever has called them is not expecting to get a WP_Error object.

So what happens is that you get a fatal error along the lines of "Fatal error: Cannot use object of type WP_Error as array in . . ." instead of the kind of helpful error handling WP_Error is supposed to provide.

I would like to use this ticket to create patches to address each of the areas where this occurs.

Functions that return WP_Error objects
(those marked with * have received the WP_Error object from elsewhere)


*get_bookmark_field
get_objects_in_term
*get_post_field
get_term
get_term_children
*get_term_field
*get_term_to_edit
get_terms
wp_get_object_terms
wp_insert_term
wp_set_object_terms
wp_update_term
wp_write_post

Attachments

errors.diff (23.2 kB) - added by filosofo on 09/18/07 16:06:03.

Change History

08/30/07 04:19:33 changed by filosofo

  • owner changed from anonymous to filosofo.

09/12/07 21:56:39 changed by ryan

  • priority changed from normal to high.

09/12/07 22:38:15 changed by filosofo

I've been working on this, but it's very involved--a wp error potentially gets returned in dozens of places. Would it be better to post one big patch or piecemeal as I'm doing it?

09/18/07 08:13:14 changed by ryan

Piecemeal. For 2.3 we can probably only do the nastier ones.

09/18/07 13:36:50 changed by santosj

Is it okay if someone submits a patch?

09/18/07 16:06:03 changed by filosofo

  • attachment errors.diff added.

09/18/07 16:06:25 changed by filosofo

I've attached what I've done so far.

09/18/07 16:32:22 changed by ryan

(In [6125]) Add checks for WP_Error. Props filosofo. see #4809

09/18/07 16:33:05 changed by ryan

general-template and widgets didn't apply cleanly.

09/21/07 15:51:01 changed by ryan

(In [6148]) Add checks for WP_Error. Props filosofo. see #4809

09/23/07 19:17:09 changed by ryan

  • milestone changed from 2.3 to 2.4.

I think we're good enough for 2.3. Moving to 2.4 to finish any remaining places.

02/20/08 17:36:14 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.