Filter uncanny-automator

automator_get_action_error_message

Filters the error message displayed when an action fails to execute.

add_filter( 'automator_get_action_error_message', $callback, 10, 7 );

Description

Filters the action error message before it's displayed. Developers can use this hook to modify, enrich, or completely change the error message passed to the user, providing more context or a user-friendly alternative to the raw error. This hook is called when an action fails during recipe execution.


Usage

add_filter( 'automator_get_action_error_message', 'your_function_name', 10, 7 );

Parameters

$message (mixed)
This parameter contains the default or previously determined error message string.
$user_id (mixed)
This parameter holds the initial error message that is being processed or potentially modified by the filter.
$action_data (mixed)
This parameter holds the ID of the user for whom the recipe is being processed.
$recipe_id (mixed)
This parameter contains the data associated with the specific action being processed, which might include configuration settings or other relevant details.
$error_message (mixed)
This parameter holds the original error message that triggered the hook.
$recipe_log_id (mixed)
This parameter provides the specific error message that was generated during the action's execution.
$args (mixed)
This parameter contains an array of additional arguments passed to the action, which can be used for more context or custom logic.

Return Value

The filtered value.


Examples

/**
 * Custom error message handler for Automator recipes.
 *
 * This function intercepts the default error message generated by the
 * automator_get_action_error_message hook and adds a specific prefix
 * if the error relates to a failed API integration for a particular user.
 *
 * @param mixed $message The original error message.
 * @param mixed $user_id The ID of the user the recipe is running for.
 * @param mixed $action_data The data associated with the action that failed.
 * @param mixed $recipe_id The ID of the recipe.
 * @param mixed $error_message The specific error message from the action.
 * @param mixed $recipe_log_id The ID of the recipe log entry.
 * @param mixed $args Additional arguments passed to the filter.
 * @return string The modified error message.
 */
add_filter( 'automator_get_action_error_message', function( $message, $user_id, $action_data, $recipe_id, $error_message, $recipe_log_id, $args ) {

    // Check if the error is related to a specific action type that might have API issues.
    // For example, let's assume $action_data['type'] could be 'send_api_request'.
    if ( isset( $action_data['type'] ) && 'send_api_request' === $action_data['type'] ) {
        // Check if the user ID is available and it's a valid user.
        if ( $user_id && absint( $user_id ) > 0 ) {
            // Add a prefix to indicate it's a user-specific API integration error.
            $prefix = sprintf( __( 'User API Error (%s): ', 'your-text-domain' ), $user_id );
            return $prefix . $message;
        }
    }

    // If no specific condition is met, return the original message.
    return $message;

}, 10, 7 );

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

src/core/lib/process/class-automator-recipe-process-complete.php:739

public function get_action_error_message( $user_id = null, $action_data = null, $recipe_id = null, $error_message = '', $recipe_log_id = null, $args = array() ) {

		$message = '';

		$possible_error_msg_keys = key_exists( 'complete_with_errors', $action_data ) || key_exists( 'complete_with_notice', $action_data ) || key_exists( 'do-nothing', $action_data );

		if ( ! empty( $error_message ) && $possible_error_msg_keys ) {

			$message = $error_message;
		}

		if ( key_exists( 'user_action_message', $args ) && ! empty( $args['user_action_message'] ) ) {

			$message = $args['user_action_message'];

			/**
			 * Append the error message if there is user_action_message.
			 *
			 * The second IF condition `$message !== $error_message` is added to prevent duplicate message.
			 *
			 * @since 4.8
			 * @see <https://secure.helpscout.net/conversation/2070532337/45265/>
			 */
			if ( ! empty( $error_message ) && $message !== $error_message ) {
				$message .= ' — ' . $error_message;
			}
		}

		return apply_filters( 'automator_get_action_error_message', $message, $user_id, $action_data, $recipe_id, $error_message, $recipe_log_id, $args );
	}

Internal Usage

Found in src/integrations/linkedin/helpers/linkedin-scheduled-posts-manager.php:97:

add_filter( 'automator_get_action_error_message', array( $this, 'filter_action_message' ), 10, 7 );

Found in src/integrations/whatsapp/actions/whatsapp-send-message-template.php:28:

add_filter( 'automator_get_action_error_message', array( $this, 'set_error_message' ), 10, 7 );

Found in src/integrations/whatsapp/actions/whatsapp-send-message.php:26:

add_filter( 'automator_get_action_error_message', array( $this, 'set_error_message' ), 10, 7 );

Found in src/integrations/instagram/traits/trait-instagram-publish-retry.php:60:

add_filter( 'automator_get_action_error_message', array( $this, 'retry_set_error_message' ), 10, 7 );
Scroll to Top