action-scheduler
action-scheduler copied to clipboard
How to debug properly?
Hi guys,
is there a guide how to debug code within a action scheduler function properly? I tried WPs build in error_log function but for some reason it does not trigger. instead i see a vague error code description in AS "Log" column like "devision by zero" but without a hint of a line of code nor a file. So each time i have to guess whats wrong. Very exhausting.
best Nic
Hi @nicmare,
I think we can improve on this and so will mark as an enhancement request.
Until then, and within the same table as your screenshot, you should be able to see both the hook and any arguments passed to the hook. With that in mind, it would seem like it should generally be possible for you to try and replicate with code looking something like this:
do_action_ref_array( $hook, array_values( $args ) );
Or, suppose for a moment there are no arguments, then via WP CLI you could simply do:
wp eval "do_action( 'the_hook' );"
This will hopefully allow you to see more complete error information. Of course, if the circumstances leading to a division-by-zero error are dynamic in nature or if the callback function is non-deterministic, then this may not get you very far: but you should still be able to start the process of debugging your callback function.
Hi @barryhughes @nicmare
This can be fixed by changing line 94 in 'classes/abstracts/ActionScheduler_Abstract_QueueRunner.php' to throw new Exception( $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine(), $e->getCode(), $e->getPrevious() );
Thanks! Though, worth noting that (as we currently support as far back as PHP 5.6) we'd ideally need an additional change within the custom error handler.
Hi @barryhughes @nicmare This can be fixed by changing line 94 in 'classes/abstracts/ActionScheduler_Abstract_QueueRunner.php' to
throw new Exception( $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine(), $e->getCode(), $e->getPrevious() );
this helps me A LOT. so much easier to identify bugs. thank you