Throw an ErrorException rather than a standard exception when an error is caught during action processing #1057
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1052
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 WooCommerce Subscriptions because AS will trigger the
action_scheduler_failed_execution
action which passes callbacks the exception that was caught.WooCommerce 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 occurred, it will point to AS, not where the error was actually thrown.This is fixed by throwing an
ErrorException
which enables specifying the file and line where the error occurred.Testing instructions
trunk
you'll notice the file and line points to AStrunk