Make WordPress Core

Opened 6 weeks ago

Last modified 5 weeks ago

#64561 new enhancement

Add to wp_trigger_error() log output information about the source of the error

Reported by: oglekler's profile oglekler Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 6.4
Component: General Keywords: needs-patch
Focuses: Cc:

Description

I've got an error in the log:

PHP Notice:  Function wpdb::prepare was called <strong>incorrectly</strong>. The query argument of wpdb::prepare() must have a placeholder. Please see <a href="https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 3.9.0.) in ***\app\public\wp-includes\functions.php on line 6131

And this line that message refers to is the line in wp_trigger_error() that calls trigger_error() and, from the debugging point of view, is pointless. Of course there are filters before, and you can find the source of the issue via debug tools, but this needs to be done additionally, when actual information that is already captured can be just printed into the log.

Change History (3)

#1 @westonruter
6 weeks ago

  • Version set to 6.4

I suppose this is why wpdb::prepare() is specifically mentioned in the error message so that a dev knows to look at that function to locate the source of the error, as opposed to going to wp-includes/functions.php on line 6131. I don't think that latter file reference can be removed since it comes from PHP, but we could look at the stack trace and add additional file name and line number for where wp_trigger_error() was called.

The same would go for the _doing_it_wrong() family of functions.

#2 @oglekler
5 weeks ago

  • Keywords needs-patch added

#3 @westonruter
5 weeks ago

  • Milestone changed from Awaiting Review to Future Release

Relatedly, [61587] just landed _wp_scripts_add_args_data() which obtains the offending function via:

<?php
$trace         = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 );
$function_name = ( $trace[1]['class'] ?? '' ) . ( $trace[1]['type'] ?? '' ) . $trace[1]['function'];
Last edited 5 weeks ago by westonruter (previous) (diff)
Note: See TracTickets for help on using tickets.