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

Printing error output when runserver fails. #1639

Merged
merged 2 commits into from
Jun 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Robo/Commands/Blt/DoctorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function executeDoctorInsideVm() {
$this->logger->error("The value of drupal_core_path in $drupal_vm_config_filepath contains an unresolved Ansible variable.");
$this->logger->error("Do not use Ansible variable placeholders for drupal_core_path.");
$this->logger->error("drupal_core_path is currently $drupal_vm_config_filepath. Please correct it.");
throw new \Exception("Unparsable value in $drupal_vm_config_filepath.");
throw new BltException("Unparsable value in $drupal_vm_config_filepath.");
}

$this->say("Drupal VM was detected. Running blt doctor inside of VM...");
Expand Down
4 changes: 2 additions & 2 deletions src/Robo/Commands/Deploy/DeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ protected function getTagName($options) {

if (empty($tag_name)) {
// @todo Validate tag name is valid. E.g., no spaces or special characters.
throw new \Exception("You must enter a valid tag name.");
throw new BltException("You must enter a valid tag name.");
}
else {
$tag_name = $options['tag'];
Expand Down Expand Up @@ -245,7 +245,7 @@ protected function addGitRemotes() {
// Add remotes and fetch upstream refs.
$git_remotes = $this->getConfigValue('git.remotes');
if (empty($git_remotes)) {
throw new \Exception("git.remotes is empty. Please define at least one value for git.remotes in blt/project.yml.");
throw new BltException("git.remotes is empty. Please define at least one value for git.remotes in blt/project.yml.");
}
foreach ($git_remotes as $remote_url) {
$this->addGitRemote($remote_url);
Expand Down
2 changes: 2 additions & 0 deletions src/Robo/Commands/Tests/BehatCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function initialize() {
* @interactConfigureBehat
* @validateMySqlAvailable
* @validateDrupalIsInstalled
* @validateSettingsFilesPresent
* @validateBehatIsConfigured
* @validateInsideVm
* @launchWebServer
Expand Down Expand Up @@ -167,6 +168,7 @@ protected function launchSelenium() {
->get('executor')
->execute($this->getConfigValue('composer.bin') . "/selenium-server-standalone -port {$this->seleniumPort} -log {$this->seleniumLogFile} > /dev/null 2>&1")
->background(TRUE)
// @todo Print output when this command fails.
->printOutput(TRUE)
->dir($this->getConfigValue('repo.root'))
->run();
Expand Down
4 changes: 2 additions & 2 deletions src/Robo/Commands/Vm/VmCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ protected function requireDrupalVm() {
}
else {
// @todo revert previous file chanages.
throw new \Exception("Unable to install Drupal VM.");
throw new BltException("Unable to install Drupal VM.");
}
}

Expand All @@ -259,7 +259,7 @@ protected function checkRequirements() {
$this->logger->error("Vagrant is not installed.");
$this->say("Please install all dependencies for Drupal VM by following the Quickstart Guide:");
$this->say("https://github.com/geerlingguy/drupal-vm#quick-start-guide");
throw new \Exception("Drupal VM requirements are missing.");
throw new BltException("Drupal VM requirements are missing.");
}
else {
$this->installVagrantPlugin('vagrant-hostsupdater');
Expand Down
3 changes: 2 additions & 1 deletion src/Robo/Common/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Acquia\Blt\Robo\Common;

use Acquia\Blt\Robo\Config\ConfigAwareTrait;
use Acquia\Blt\Robo\Exceptions\BltException;
use GuzzleHttp\Client;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
Expand Down Expand Up @@ -189,7 +190,7 @@ public function wait(callable $callable, array $args, $message = '') {
usleep($checkEvery * 1000);
}

throw new \Exception("Timed out");
throw new BltException("Timed out.");
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Robo/Config/DefaultConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function getRepoRoot() {
}
}

throw new \Exception('Could not find repository root directory!');
throw new BltException('Could not find repository root directory!');
}

/**
Expand All @@ -66,7 +66,7 @@ protected function getBltRoot() {
}
}

throw new \Exception('Could not find the Drupal docroot directory');
throw new BltException('Could not find the Drupal docroot directory');
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Robo/Datastore/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected function getFileName($key, $writable = FALSE) {
}

if (!$key) {
throw new \Exception('Could not save data to a file because it is missing an ID');
throw new BltException('Could not save data to a file because it is missing an ID');
}
return $this->directory . '/' . $key;
}
Expand All @@ -142,13 +142,13 @@ protected function ensureDirectoryWritable() {
// Reality check to prevent stomping on the local filesystem if there is
// something wrong with the config.
if (!$this->directory) {
throw new \Exception('Could not save data to a file because the path setting is mis-configured.');
throw new BltException('Could not save data to a file because the path setting is mis-configured.');
}

$writable = is_dir($this->directory) || (!file_exists($this->directory) && @mkdir($this->directory, 0777, TRUE));
$writable = $writable && is_writable($this->directory);
if (!$writable) {
throw new \Exception(
throw new BltException(
'Could not save data to a file because the path {path} cannot be written to.',
['path' => $this->directory]
);
Expand Down
36 changes: 25 additions & 11 deletions src/Robo/Hooks/ValidateHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Acquia\Blt\Robo\Common\IO;
use Acquia\Blt\Robo\Config\ConfigAwareTrait;
use Acquia\Blt\Robo\Exceptions\BltException;
use Acquia\Blt\Robo\Inspector\InspectorAwareInterface;
use Acquia\Blt\Robo\Inspector\InspectorAwareTrait;
use Consolidation\AnnotatedCommand\CommandData;
Expand Down Expand Up @@ -38,7 +39,7 @@ class ValidateHook implements ConfigAwareInterface, LoggerAwareInterface, Inspec
*/
public function validateDocrootIsPresent(CommandData $commandData) {
if (!$this->getInspector()->isDocrootPresent()) {
throw new \Exception("Unable to find Drupal docroot.");
throw new BltException("Unable to find Drupal docroot.");
}
}

Expand All @@ -49,7 +50,7 @@ public function validateDocrootIsPresent(CommandData $commandData) {
*/
public function validateRepoRootIsPresent(CommandData $commandData) {
if (empty($this->getInspector()->isRepoRootPresent())) {
throw new \Exception("Unable to find repository root.");
throw new BltException("Unable to find repository root.");
}
}

Expand All @@ -63,7 +64,7 @@ public function validateDrupalIsInstalled(CommandData $commandData) {
->isDrupalInstalled()
) {

throw new \Exception("Drupal is not installed");
throw new BltException("Drupal is not installed");
}
}

Expand All @@ -73,14 +74,12 @@ public function validateDrupalIsInstalled(CommandData $commandData) {
* @hook validate @validateSettingsFileIsValid
*/
public function validateSettingsFileIsValid(CommandData $commandData) {
if (!$this->getInspector()
->isDrupalSettingsFilePresent()
) {
throw new \Exception("Could not find settings.php for this site.");
if (!$this->getInspector()->isDrupalSettingsFilePresent()) {
throw new BltException("Could not find settings.php for this site.");
}

if (!$this->getInspector()->isDrupalSettingsFileValid()) {
throw new \Exception("BLT settings are not included in settings file.");
throw new BltException("BLT settings are not included in settings file.");
}
}

Expand All @@ -91,7 +90,7 @@ public function validateSettingsFileIsValid(CommandData $commandData) {
*/
public function validateBehatIsConfigured(CommandData $commandData) {
if (!$this->getInspector()->isBehatConfigured()) {
throw new \Exception("Behat is not configured properly. Please run `blt doctor` to diagnose the issue.");
throw new BltException("Behat is not configured properly. Please run `blt doctor` to diagnose the issue.");
}
}

Expand All @@ -103,8 +102,23 @@ public function validateBehatIsConfigured(CommandData $commandData) {
public function validateMySqlAvailable() {
if (!$this->getInspector()->isMySqlAvailable()) {
// @todo Prompt to fix.
throw new \Exception("MySql is not available. Please run `blt doctor` to diagnose the issue.");
throw new BltException("MySql is not available. Please run `blt doctor` to diagnose the issue.");
}
}

/**
* Validates that required settings files exist.
*
* @hook validate @validateSettingsFilesPresent
*/
public function validateSettingsFilesPresent() {
if (!$this->getInspector()->isHashSaltPresent()) {
throw new BltException("salt.txt is not present. Please run `blt setup:settings` to generate it.");
}
if (!$this->getInspector()->isDrupalLocalSettingsFilePresent()) {
throw new BltException("Could not find settings.php for this site.");
}
// @todo Look for local.drushrc.php.
}

/**
Expand All @@ -114,7 +128,7 @@ public function validateMySqlAvailable() {
*/
public function validateInsideVm() {
if ($this->getInspector()->isDrupalVmLocallyInitialized() && !$this->getInspector()->isVmCli()) {
throw new \Exception("You must run this command inside Drupal VM, or else do not use Drupal VM at all. Execute `vagrant ssh` and then execute the command, or else change drush.aliases.local in blt/project.local.yml.");
throw new BltException("You must run this command inside Drupal VM, or else do not use Drupal VM at all. Execute `vagrant ssh` and then execute the command, or else change drush.aliases.local in blt/project.local.yml.");
}
}

Expand Down
26 changes: 24 additions & 2 deletions src/Robo/Hooks/WebServerHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

use Acquia\Blt\Robo\Common\IO;
use Acquia\Blt\Robo\Config\ConfigAwareTrait;
use Acquia\Blt\Robo\Exceptions\BltException;
use Acquia\Blt\Robo\Inspector\InspectorAwareInterface;
use Acquia\Blt\Robo\Inspector\InspectorAwareTrait;
use League\Container\ContainerAwareInterface;
use League\Container\ContainerAwareTrait;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Robo\Contract\ConfigAwareInterface;
use Symfony\Component\Filesystem\Filesystem;

/**
*
Expand All @@ -35,8 +37,28 @@ public function launchWebServer() {
$this->killWebServer();
$this->say("Launching PHP's internal web server via drush.");
$this->logger->info("Running server at $this->serverUrl...");
$this->getContainer()->get('executor')->drush("runserver $this->serverUrl > /dev/null")->background(TRUE)->run();
$this->getContainer()->get('executor')->waitForUrlAvailable($this->serverUrl);

$fs = new Filesystem();
$fs->mkdir([$this->getConfigValue('repo.root') . '/tmp']);
$log_file = $this->getConfigValue('repo.root') . '/tmp/runserver.log';

/** @var \Acquia\Blt\Robo\Common\Executor $executor */
$executor = $this->getContainer()->get('executor');
$result = $executor
->drush("runserver $this->serverUrl")
->background(TRUE)
->run();

try {
$executor->waitForUrlAvailable($this->serverUrl);
}
catch (\Exception $e) {
if (!$result->wasSuccessful() && file_exists($log_file)) {
$output = file_get_contents($log_file);
unlink($log_file);
throw new BltException($output);
}
}
}
}

Expand Down
22 changes: 17 additions & 5 deletions src/Robo/Inspector/Inspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Robo\Contract\BuilderAwareInterface;
use Robo\Contract\ConfigAwareInterface;
use Symfony\Component\Filesystem\Filesystem;
use Robo\Contract\VerbosityThresholdInterface;

/**
* Class Inspector.
Expand Down Expand Up @@ -47,7 +48,7 @@ class Inspector implements BuilderAwareInterface, ConfigAwareInterface, LoggerAw
/**
* @var array
*/
protected $drupalVmStatus = [];
protected $drupalVmStatus = NULL;

/**
* @var \Symfony\Component\Filesystem\Filesystem
Expand Down Expand Up @@ -138,6 +139,16 @@ public function isDrupalSettingsFilePresent() {
return file_exists($this->getConfigValue('drupal.settings_file'));
}

/**
* Determines if salt.txt file exists.
*
* @return bool
* TRUE if file exists.
*/
public function isHashSaltPresent() {
return file_exists($this->getConfigValue('repo.root') . '/salt.txt');
}

/**
* Determines if Drupal local.settings.php file exists.
*
Expand Down Expand Up @@ -267,7 +278,7 @@ public function isDrupalVmLocallyInitialized() {
$status = $this->getDrupalVmStatus();
$machine_name = $this->getConfigValue('project.machine_name');
$initialized = !empty($status[$machine_name])
&& file_exists($this->getConfigValue('repo.root') . '/box/config.yml');
&& file_exists($this->getConfgValue('repo.root') . '/box/config.yml');
$statement = $initialized ? "is" : "is not";
$this->logger->debug("Drupal VM $statement initialized.");

Expand Down Expand Up @@ -536,7 +547,7 @@ public function isSimpleSamlPhpInstalled() {
* An array of status data.
*/
protected function getDrupalVmStatus() {
if (empty($this->drupalVmStatus)) {
if (is_null($this->drupalVmStatus)) {
$this->setDrupalVmStatus();
}
return $this->drupalVmStatus;
Expand All @@ -547,12 +558,13 @@ protected function getDrupalVmStatus() {
*/
protected function setDrupalVmStatus() {
$result = $this->executor->execute("vagrant status --machine-readable")
->printOutput(FALSE)
->printMetadata(FALSE)
->interactive(FALSE)
->printMetadata(TRUE)
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERY_VERBOSE)
->run();
$output = $result->getMessage();
if (!$result->wasSuccessful() || !$output) {
$this->drupalVmStatus = [];
return FALSE;
}
$lines = explode("\n", $output);
Expand Down
10 changes: 9 additions & 1 deletion src/Robo/Wizards/SetupWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ class SetupWizard extends Wizard {
* Executes blt setup:settings command.
*/
public function wizardGenerateSettingsFiles() {
$missing = FALSE;
if (!$this->getInspector()->isDrupalLocalSettingsFilePresent()) {
$this->logger->warning("<comment>{$this->getConfigValue('drupal.local_settings_file')}</comment> is missing.");
$confirm = $this->confirm("Do you want to generate this required settings file?");
$missing = TRUE;
}
elseif (!$this->getInspector()->isHashSaltPresent()) {
$this->logger->warning("<comment>salt.txt</comment> is missing.");
$missing = TRUE;
}
if ($missing) {
$confirm = $this->confirm("Do you want to generate this required settings file(s)?");
if ($confirm) {
$bin = $this->getConfigValue('composer.bin');
$this->executor
Expand Down