Problem/Motivation
I discovered this while working on #3166602: Ensure media_filter → media_embed mapping does not cause fatal errors and subsequently #3166930: Migrated filters may have invalid/incomplete settings applied.
If a fatal PHP error occurs in the middle of a migration, it leaves the migration in a weird state:
- the message of the fatal error is not logged into the Migration system's messages tables, but only in the PHP error log and into watchdog
- the migration is left in the
\Drupal\migrate\Plugin\MigrationInterface::STATUS_IMPORTING
state - therefore the migration is effectively "stuck", and you need to manually unstuck it
Steps to reproduce
See the STR in #3166930: Migrated filters may have invalid/incomplete settings applied.
Proposed resolution
Set a custom exception handler while in MigrateExecutable
, because these are currently caught by _drupal_exception_handler()
, so surely the migration system can do the same, but provide extra context?
- In PHP 7, fatal errors can be caught! So let's catch them, and treat them like exceptions. See https://www.php.net/manual/en/language.errors.php7.php→ see #2👀
- We currently only have
/** * Migration error. */ const MESSAGE_ERROR = 1; /** * Migration warning. */ const MESSAGE_WARNING = 2; /** * Migration notice. */ const MESSAGE_NOTICE = 3; /** * Migration info. */ const MESSAGE_INFORMATIONAL = 4;
Also add
MESSAGE_FATAL_ERROR
so that it's possible to communicate this is even worse thanMESSAGE_ERROR
. → see #3👀
Remaining tasks
- Update issue summary (Novice).
- Add tests.
User interface changes
Fatal errors also show up.
API changes
Addition: \Drupal\migrate\Plugin\MigrationInterface:MESSAGE_FATAL_ERROR
.
Data model changes
None.
Release notes snippet
Fatal errors while running a migration no longer cause the migration system to crash.