diff --git a/src/MigrateBatchExecutable.php b/src/MigrateBatchExecutable.php index ec3d48d..4f0310a 100644 --- a/src/MigrateBatchExecutable.php +++ b/src/MigrateBatchExecutable.php @@ -159,9 +159,11 @@ public function prepareBatch() { 'finished' => [$this, 'finishBatch'], ]; } - else { - throw new \Exception('Migration failed.'); + + if ($this->enqueueException) { + throw new \Exception("Migration ({$this->migration->id()}) failed. Wrapped exception: {$this->enqueueException->getMessage()}", previous: $this->enqueueException); } + throw new \Exception("Migration ({$this->migration->id()}) failed."); } /** @@ -180,6 +182,13 @@ public function teardownMigration() { $this->migration->setStatus(MigrationInterface::STATUS_IDLE); } + /** + * Stash any exception encountered during enqueueing, so it can be reported. + * + * @var \Exception|null + */ + protected ?\Exception $enqueueException = NULL; + /** * Populate the target queue with the rows of the given migration. * @@ -218,6 +227,7 @@ protected function enqueue() { ), 'error' ); + $this->enqueueException = $e; return MigrationInterface::RESULT_FAILED; } @@ -232,6 +242,7 @@ protected function enqueue() { $this->message->display( $this->t('Migration failed with source plugin exception: @e', ['@e' => $e]), 'error'); $this->migration->setStatus(MigrationInterface::STATUS_IDLE); + $this->enqueueException = $e; return MigrationInterface::RESULT_FAILED; }