Skip to content

Commit 5ca4c55

Browse files
committed
Handle SchemaException with improved validation and integrate additional task steps in MAML recipes
1 parent a1a4738 commit 5ca4c55

4 files changed

Lines changed: 181 additions & 218 deletions

File tree

src/Deployer.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Deployer\Command\TreeCommand;
2121
use Deployer\Command\WorkerCommand;
2222
use Deployer\Component\Pimple\Container;
23+
use Deployer\Exception\SchemaException;
2324
use Deployer\Executor\Master;
2425
use Deployer\Host\Host;
2526
use Deployer\Host\HostCollection;
@@ -274,18 +275,24 @@ public static function run(string $version, ?string $deployFile): void
274275

275276
public static function printException(OutputInterface $output, Throwable $exception): void
276277
{
277-
$class = get_class($exception);
278-
$file = basename($exception->getFile());
279-
$output->writeln([
280-
"<fg=white;bg=red> {$class} </> <comment>in {$file} on line {$exception->getLine()}:</>",
281-
"",
282-
implode("\n", array_map(function ($line) {
283-
return " " . $line;
284-
}, explode("\n", $exception->getMessage()))),
285-
"",
286-
]);
287-
if ($output->isDebug()) {
288-
$output->writeln($exception->getTraceAsString());
278+
if ($exception instanceof SchemaException) {
279+
$output->writeln([
280+
"<fg=white;bg=red> Schema error </> {$exception->getMessage()}",
281+
]);
282+
} else {
283+
$class = get_class($exception);
284+
$file = basename($exception->getFile());
285+
$output->writeln([
286+
"<fg=white;bg=red> {$class} </> <comment>in {$file} on line {$exception->getLine()}:</>",
287+
"",
288+
implode("\n", array_map(function ($line) {
289+
return " " . $line;
290+
}, explode("\n", $exception->getMessage()))),
291+
"",
292+
]);
293+
if ($output->isDebug()) {
294+
$output->writeln($exception->getTraceAsString());
295+
}
289296
}
290297

291298
if ($exception->getPrevious()) {

src/Exception/SchemaException.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,12 @@
1010

1111
namespace Deployer\Exception;
1212

13-
class SchemaException extends \RuntimeException {}
13+
use Throwable;
14+
15+
class SchemaException extends \RuntimeException
16+
{
17+
public function __construct(string $message = "", ?Throwable $previous = null)
18+
{
19+
parent::__construct($message, 0, $previous);
20+
}
21+
}

0 commit comments

Comments
 (0)