Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#57273 new defect (bug)

Fatal error not trapped in do_action()

Reported by: charlesgodwin's profile charlesgodwin Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.1.1
Component: General Keywords: reporter-feedback
Focuses: Cc:

Description

I encountered a problem this week during a do_action. It was while processing a order complete action in WooCommerce. One of the add_action modules failed trying to instantiate a class. The cause has been fixed but the bug is:
There was nothing in the error log and the rest of the registered actions did not complete, leaving a partially complete "action".

I think the proper behaviour should be for the do_action function to wrap each "registered" processing a try / catch block. If it catches an error it logs it to the error log. After that....? is open to debate. I think the rest of the actions should be invoked but others might argue that the exception should be rethrown and nothing more takes place. I'll leave it to your experience to decide.

I suspect the same behaviour in do_filter, but I have not investigated.
we are using PHP 8.0.25

Change History (2)

#1 @johnbillion
2 years ago

  • Keywords reporter-feedback added

@charlesgodwin What's the underlying error that was triggered? Was it a PHP fatal error? If so, this should be logged in the PHP error log by default, if not then there is a problem with the error logging configuration on your site that you should take a look at. Possibly the WP_DEBUG_LOG constant in your wp-config.php file, otherwise the error_reporting and error_log directives in your php.ini file.

Wrapping each action in a try ... catch and still running subsequent actions after one of them throws an exception could introduce its own problems, for example actions can make assumptions about what has happened in prior actions and therefore cause unintended behaviour if they run when a prior one hasn't completed fully.

#2 @charlesgodwin
2 years ago

The error was Fatal error: Uncaught Error: Cannot call constructor. It was trying to instantiate an object that used the class name as a function instead of __construct

WP_DEBUG_LOG is not set. Here are the other values.

error_log      /home/ogsonca/logs/ogs_on_ca.php.error.log
error_reporting 32759

I understand the problem of the try/catch block and I don't have a magic answer. My problem was that only way I was able to find this is that I could run the bad code outside of WordPress.

Note: See TracTickets for help on using tickets.