Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a Drupal8ForkingLoop to handle AssertionErrors that get thrown #2635

Closed

Conversation

damiankloip
Copy link
Contributor

@damiankloip damiankloip commented Feb 22, 2017

When using Drupal 8 and assertions are enabled using PHP7 (PHP5 we support our own \AssertionError class which does extend Exception), which is very likely in development, our shell cannot handle AssertionErrors. This is most evident when the FokingLoop tries to serialize the container to keep state in the REPL. This is not just the container directly, but E.g. The entity manager has a reference which tries to get serialized too.

Alas, we need to override the whole ForkingLoop implementation that ships with Psysh to catch the exception in the correct place. We then avoid errors like this:

>>> exit
Exit:  Goodbye.
 [error]  AssertionError: The container was serialized. in assert() (line 29 of /Users/damianlee/Sites/D8/core/lib/Drupal/Core/DependencyInjection/Container.php) #0 /Users/damianlee/Sites/D8/core/lib/Drupal/Core/DependencyInjection/Container.php(29): assert(false, 'The container w...')
#1 [internal function]: Drupal\Core\DependencyInjection\Container->__sleep()
#2 ../drush/vendor/psy/psysh/src/Psy/ExecutionLoop/ForkingLoop.php(165): serialize(Object(Drupal\Core\Entity\EntityManager))
#3 ../drush/vendor/psy/psysh/src/Psy/ExecutionLoop/ForkingLoop.php(82): Psy\ExecutionLoop\ForkingLoop->serializeReturn(Array)
#4 ../drush/vendor/psy/psysh/src/Psy/Shell.php(308): Psy\ExecutionLoop\ForkingLoop->run(Object(Drush\Psysh\Shell))
#5 ../drush/vendor/symfony/console/Application.php(124): Psy\Shell->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Psy\Output\ShellOutput))
#6 ../drush/vendor/psy/psysh/src/Psy/Shell.php(273): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Psy\Output\ShellOutput))
#7 ../drush/lib/Drush/Commands/core/CliCommands.php(101): Psy\Shell->run()
#8 [internal function]: Drush\Commands\core\CliCommands->cli(Array)
#9 ../drush/vendor/consolidation/annotated-command/src/CommandProcessor.php(180): call_user_func_array(Array, Array)
#10 ../drush/vendor/consolidation/annotated-command/src/CommandProcessor.php(129): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#11 ../drush/vendor/consolidation/annotated-command/src/CommandProcessor.php(104): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#12 ../drush/includes/annotationcommand_adapter.inc(240): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#13 ../drush/includes/command.inc(199): annotationcommand_adapter_process_command()
#14 ../drush/lib/Drush/Boot/BaseBoot.php(73): drush_dispatch(Array)
#15 ../drush/includes/preflight.inc(93): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#16 ../drush/drush.php(11): drush_main()
#17 {main}.

} catch (\Exception $e) {
// we'll just ignore this one...
}
catch (\AssertionError $e) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really the part we need, the rest is copied from the Psy\ElavuationLoop\ForkingLoop class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether it would be easier to fix that maybe upstream somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought about that first, but Psysh supports PHP5.6 and above. So we would need to add some \AssertionError exception like Drupal does. Which I think might be a no go... at least until it was only support PHP7.

@dawehner
Copy link
Contributor

dawehner commented Feb 22, 2017 via email

@damiankloip
Copy link
Contributor Author

Yeah, seems it doesn't actually break PHP. It's still kind of dubious though IMO. I have made an upstream PR anyway bobthecow/psysh#358. Let's see. Otherwise, it's Drupal's fault for implementing this in the container really.

@damiankloip
Copy link
Contributor Author

Looks like upstream PR is fine! 🎉 Let's leave this one until that is merged.

@dawehner
Copy link
Contributor

dawehner commented Feb 22, 2017 via email

@damiankloip
Copy link
Contributor Author

You'd think that, but composer will still get the latest version (currently 0.8.1)

@dawehner
Copy link
Contributor

dawehner commented Feb 22, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants