WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#18512 closed enhancement (duplicate)

Add backtrace details to _doing_it_wrong output

Reported by: chrisjean Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Warnings/Notices Keywords: has-patch needs-testing
Focuses: Cc:

Description

The _doing_it_wrong function is great for notifying that there is a problem, but it doesn't do much to help find out where the problem originates. I made a first stab at adding some backtracking information and have the proposed patch attached.

It outputs something like the following:

Notice: wp_enqueue_script was called <strong>incorrectly</strong>. Scripts and styles should not be registered or enqueued until the <code>wp_enqueue_scripts</code>, <code>admin_enqueue_scripts</code>, or <code>init</code> hooks. (This message was added in version 3.3.) (Called by wp-content/plugins/bad-plugin/bad-plugin.php line 23) in wp-includes/functions.php on line 3523

Please try it out, and let me know if any modifications need to be made for specific cases. I'm open to completely changing the way the information is presented, I just want to be able to know from where the issue originated so that I can quickly track it down as it often shows up when I activate other developer's code.

Attachments (1)

add-backtrace-to-doing_it_wrong.diff (887 bytes) - added by chrisbliss18 4 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 @scribu4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

You can see the backtrace for any error by creating your own error handler.

Example: https://gist.github.com/625769

Also, duplicate of #18453

comment:2 @chrisbliss184 years ago

Definitely a duplicate. Thanks for that. I'm always terrible at finding related tickets. One day, I might figure out the magic to find such things.

Beyond that, I must say that your response is why I frequently hate submitting patches.

I saw a notice that someone (at least Nacin as he coded it) felt added value to core. However, I found this notice to be lacking as it essentially amounted to "some code is misbehaving, but I'm not going to tell you what code is at fault."

I thought, "I can quickly add a backtrace output to make the notice more valuable and immediately usable," and began working on a patch.

Your response of being able to add a backtrace to anything doesn't help anybody. I know that I can get a backtrace of anything I want, I did so when I made this patch. Clearly I don't need to be educated on this. I made this patch not for me but for other developers that may not know the tricks you or I do. Being able to provide them relevant feedback for possible problems rather than "something went wrong, I hope you know enough to figure out what and where" is the least we can do.

comment:3 @scribu4 years ago

Sorry to be unhelpful again, but you should make your case on the other ticket.

It's my fault as well, for mentioning the error handler.

So, let's continue this on #18453

Note: See TracTickets for help on using tickets.