Action
uncanny-automator-pro
automator_pro_loop_entry_error
Fires when a loop entry in Automator Pro encounters an error during execution.
add_action( 'automator_pro_loop_entry_error', $callback, 10, 4 );
Description
Fires when a loop entry encounters a fatal error during Uncanny Automator Pro execution. Developers can use this hook to log or handle loop entry errors, potentially retrying failed entries or notifying administrators. It's crucial for debugging and ensuring robust automation workflows.
Usage
add_action( 'automator_pro_loop_entry_error', 'your_function_name', 10, 4 );
Parameters
-
$loop_id(mixed) - The `$loop_id` parameter identifies the specific loop instance that encountered an error.
-
$recipe_flow(mixed) - This parameter contains the unique identifier for the current loop execution.
-
$error(mixed) - This parameter contains the structured recipe flow that the loop is currently processing.
-
$args(mixed) - This parameter contains a constant representing the status of a completed action with errors.
Examples
add_action( 'automator_pro_loop_entry_error', 'my_custom_automator_error_handler', 10, 5 );
/**
* Handles errors that occur within Uncanny Automator Pro loops.
*
* This function is triggered when a fatal error occurs within an Automator Pro loop.
* It logs the error and potentially flags the Automator entry as having completed with errors.
*
* @param mixed $loop_id The ID of the loop that encountered an error.
* @param mixed $recipe_flow The current recipe flow being executed.
* @param mixed $error The error message or object.
* @param mixed $automator_status The status indicating completion with errors (e.g., Automator_Status::COMPLETED_WITH_ERRORS).
* @param mixed $args Additional arguments passed to the loop execution.
*/
function my_custom_automator_error_handler( $loop_id, $recipe_flow, $error, $automator_status, $args ) {
// Ensure we have a valid Automator status indicating an error.
if ( Automator_Status::COMPLETED_WITH_ERRORS !== $automator_status ) {
return;
}
// Decode the recipe flow actions if it's encoded as JSON.
$recipe_flow_actions = json_decode( $recipe_flow, true );
// Log the error to the WordPress debug log for easier debugging.
error_log(
sprintf(
'Uncanny Automator Pro Loop Error Detected! Loop ID: %s, Error: %s, Recipe Flow Actions: %s',
print_r( $loop_id, true ),
print_r( $error, true ),
print_r( $recipe_flow_actions, true )
)
);
// In a real-world scenario, you might want to:
// 1. Update the specific Automator entry status to reflect the error.
// 2. Send an email notification to the site administrator.
// 3. Trigger a specific recovery process if applicable.
// Example: If $args contains a recipe log ID, you might try to update its status.
if ( isset( $args['recipe_log_id'] ) && ! empty( $args['recipe_log_id'] ) ) {
// This is a placeholder. You would need to interact with Uncanny Automator's
// internal classes or functions to update the log status.
// For instance, you might have a helper class to manage logs.
// Example: Uncanny_Automator_Pro_Helpers::update_recipe_log_status( $args['recipe_log_id'], $automator_status );
}
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/core/loops/loop/execute.php:309
uncanny-automator-pro/src/core/loops/loop/execute.php:420
private function handle_unexpected_bad_errors() {
$recipe_process = Automator_Recipe_Process_Complete::get_instance();
$loop_id = $this->get_loop_id();
$recipe_flow = $this->recipe_structure->retrieve();
$recipe_id = $this->get_recipe_id();
$user_id = $this->get_user_id();
$recipe_log_id = $this->get_recipe_log_id();
$args = $this->get_process_args();
register_shutdown_function(
function () use ( $recipe_process, $loop_id, $recipe_flow, $recipe_id, $user_id, $recipe_log_id, $args ) {
$error = error_get_last();
if ( null !== $error && ( E_USER_ERROR === $error['type'] || E_ERROR === $error['type'] ) ) { // Fatal error has occured.
do_action( 'automator_pro_loop_entry_error', $loop_id, wp_json_encode( $recipe_flow->get( 'actions' ) ), $error['message'], Automator_Status::COMPLETED_WITH_ERRORS, $args );
$recipe_process->recipe( $recipe_id, $user_id, $recipe_log_id, $args );
// Ask queue to resume next process?
}
}
);
}
Internal Usage
Found in uncanny-automator-pro/src/core/loops/process-hooks-callbacks.php:44:
add_action( 'automator_pro_loop_entry_error', array( $this, 'flag_entry_with_error' ), 10, 5 );