You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the ActionScheduler_Abstract_QueueRunner::process_action() function AS sets an error handler and any E_USER_ERROR or E_RECOVERABLE_ERROR error that occurs while processing the action is caught and thrown as an exception instead.
This is super handy for Woo Subscriptions because AS will trigger the action_scheduler_failed_execution action which passes callbacks the exception that was caught.
Woo Subscriptions uses this hook to log data about why our subscription-related scheduled actions have failed, however something I noticed today is that because AS is creating a new exception, if you use the $exception->getFile()$exception->getLine() helpers to point to where the exception occured, it will point to AS, not where the error was actually thrown.
Something like that above will result in the following:
This is a fatal error in .../woocommerce/packages/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php:63
If you use ErrorException instead and pass the file and line number params, callbacks attached to the action_scheduler_failed_execution can more accurately determine where the error is occurring.
To replicate
Add the following code snippet to trigger an error and log the exception.
// Trigger a user error on action schedule execute.add_action( 'action_scheduler_begin_execute', function() {
trigger_error( 'Oops!', E_USER_ERROR );
} );
// Log the exception caught.add_action( 'action_scheduler_failed_execution', function ( $action_id, $e, $context ) {
$message = sprintf( 'Action failed: %s in %s: %d', $e->getMessage(), $e->getFile(), $e->getLine() );
error_log( $message );
ActionScheduler_Logger::instance()->log( $action_id, $message );
}, 10, 3 );
Run any scheduled action.
When the event runs, you should see the following in your debug log or on the scheduled action log.
Note that the file and line number point to AS files.
Action failed: Oops! in /public/wp-content/plugins/woocommerce/packages/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php: 95
Using ErrorException and passing the additional file and line number args instead of an standard exception here, should do the trick.
Thanks for suggesting this, @james-allan. It makes sense to me and actually we have a very similar existing report, but my sense of things is that what you've proposed here is probably the preferable course of action. I'll follow up later and we can close the other issue, unless there is any disagreement/reasons we've missed.
Marking as an enhancement and, of course, we'd be very receptive to a pull request for this (though no problem if you don't have time).
Description
In the
ActionScheduler_Abstract_QueueRunner::process_action()
function AS sets an error handler and anyE_USER_ERROR
orE_RECOVERABLE_ERROR
error that occurs while processing the action is caught and thrown as an exception instead.This is super handy for Woo Subscriptions because AS will trigger the
action_scheduler_failed_execution
action which passes callbacks the exception that was caught.Woo Subscriptions uses this hook to log data about why our subscription-related scheduled actions have failed, however something I noticed today is that because AS is creating a new exception, if you use the
$exception->getFile()
$exception->getLine()
helpers to point to where the exception occured, it will point to AS, not where the error was actually thrown.eg
Something like that above will result in the following:
If you use
ErrorException
instead and pass the file and line number params, callbacks attached to theaction_scheduler_failed_execution
can more accurately determine where the error is occurring.To replicate
Using
ErrorException
and passing the additional file and line number args instead of an standard exception here, should do the trick.action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php
Line 63 in 5fb6552
The text was updated successfully, but these errors were encountered: