Skip to content

Commit

Permalink
Improve fail message (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
gseidel authored Aug 18, 2022
1 parent cb27a94 commit 9ded151
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function run(InputInterface $input): int
$this->application->add(new NpmReleaseCommand('npm-release'));
$this->application->add(new VendorSymlinkCommand('vendor-symlink'));
$this->application->setDefaultCommand('interactive');

return $this->application->run($input);
}
}
9 changes: 9 additions & 0 deletions src/BinConsoleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Enhavo\Component\Cli;

use Enhavo\Component\Cli\Exception\CommandFailException;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;

Expand Down Expand Up @@ -40,6 +41,14 @@ public function existsConsoleCommand($command)
$process = new Process([$path]);
$process->run();

if (!$process->isSuccessful()) {
$errorOutput = $process->getErrorOutput();
if (empty($errorOutput)) {
$errorOutput = $process->getOutput();
}
throw new CommandFailException($errorOutput);
}

$output = $process->getOutput();
$errorOutput = $process->getErrorOutput();
if ($process->getExitCode() !== 0) {
Expand Down
8 changes: 8 additions & 0 deletions src/Exception/CommandFailException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Enhavo\Component\Cli\Exception;

class CommandFailException extends \Exception
{

}
22 changes: 14 additions & 8 deletions src/Subroutine/Migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Enhavo\Component\Cli\AbstractSubroutine;
use Enhavo\Component\Cli\Configuration\Configuration;
use Enhavo\Component\Cli\Exception\CommandFailException;
use Enhavo\Component\Cli\SubroutineInterface;
use Enhavo\Component\Cli\Task\CreateEnv;
use Enhavo\Component\Cli\Task\CreateMigrations;
Expand All @@ -27,14 +28,19 @@ public function __construct(InputInterface $input, OutputInterface $output, Ques

public function __invoke(): int
{
(new ExecuteMigrations($this->input, $this->output, $this->questionHelper))();
(new CreateEnv($this->input, $this->output, $this->questionHelper, $this->configuration))();
(new CreateMigrations($this->input, $this->output, $this->questionHelper))();
$execute = (new ExecuteMigrations($this->input, $this->output, $this->questionHelper))();
if ($execute !== Command::SUCCESS) {
(new DoctrineForceUpdate($this->input, $this->output, $this->questionHelper))->setDefaultAnswer(self::ANSWER_NO);
try {
(new ExecuteMigrations($this->input, $this->output, $this->questionHelper))();
(new CreateEnv($this->input, $this->output, $this->questionHelper, $this->configuration))();
(new CreateMigrations($this->input, $this->output, $this->questionHelper))();
$execute = (new ExecuteMigrations($this->input, $this->output, $this->questionHelper))();
if ($execute !== Command::SUCCESS) {
(new DoctrineForceUpdate($this->input, $this->output, $this->questionHelper))->setDefaultAnswer(self::ANSWER_NO);
}
return Command::SUCCESS;
} catch(CommandFailException $exception) {
$this->output->writeln(sprintf('An error occured'));
$this->output->writeln(sprintf('<error>%s</error>', $exception->getMessage()));
return Command::FAILURE;
}

return Command::SUCCESS;
}
}

0 comments on commit 9ded151

Please sign in to comment.