Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In function batch_example_finished(), if an error occurs during batch processing, the callback function reports the arguments array of the first remaining operation. The wrong index of $error_operation is used.
The line
'@args' => print_r($error_operation[0], TRUE),
Should be
'@args' => print_r($error_operation[1], TRUE),
A minor one, but new developers may easily reproduce it in their code.
Comment | File | Size | Author |
---|---|---|---|
#1 | examples-wrong_error_operation_index-2230575-1.patch | 573 bytes | Wtower |
Comments
Comment #1
Wtower CreditAttribution: Wtower commentedPatch included.
Comment #2
Mile23I'm not sure why it's wrong. The difference between 0 and 1 is here, from
batch_example_batch_1()
:So ostensibly your patch will show the operation text whereas currently it shows the $nid.
Unless I'm completely off the mark...
It would be great to have a test that demonstrates this. Maybe create a node, call
batch_example_batch_1()
to load up the batch, then delete the node to get an expected error when the batch is run.Comment #3
Mile23Comment #4
Wtower CreditAttribution: Wtower commented$error_operation in batch_example_finished() is the first element of the remaining $operations in case of error:
$operations is an array defined in batch_example_batch_1() and batch_example_batch_2(). A look at $error_operation content from batch 1 if I trigger an error on the very first operation:
And from batch 2:
In case of error, batch_example_finished() gives the followng message:
So it will be: "An error occurred while processing batch_example_op_1 with arguments : batch_example_op_1" whereas I believe @args should display a dump of the second element of the array which is Node ID and 'Operation 0' for batch 1 or 'Operation 0' for batch 2.
Comment #5
jungleNo activity for over 9 years. I am closing this. Please feel free to reopen if necessary.
Thanks!