How to terminate a batch when an error occurs I've read this: http://api.drupal.org/api/drupal/includes%21form.inc/function/batch_set/6 and through the source code, but I cannot see how a batch operation can flag that an error has occurred to show the error message.

I can set $context['finished'] = 1.0; to end the batch, but I cannot see how to set $current_set['success'] to FALSE to abort the batch and show the error message to the user.

How is this done? Is there a good example somewhere?
To set $current_set['success'] to FALSE, you can use the following code.

$current_set = &amp;_batch_current_set();
$current_set['success'] = FALSE;


To set the messages to show to the users, you can use the following code.

$batch_context['results'][] = 'The error to be shown to the user';
$batch_context['finished'] = 1.0;


$batch_context is the last argument passed to the operation callback.

The "finished" callback receives $current_set['success'], and $batch_context['results'] respectively as first, and second argument. It can show the errors to the users using drupal_set_message().

References


_batch_process()
_batch_finished()