From a9520e6fc0156090c58ae8c4e73fe1ecf5ae51cd Mon Sep 17 00:00:00 2001 From: Mischa Braam Date: Tue, 23 Jan 2024 12:48:40 +0100 Subject: [PATCH] Prevent crash when docker is not running --- cli/ValetPlus/AbstractDockerService.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cli/ValetPlus/AbstractDockerService.php b/cli/ValetPlus/AbstractDockerService.php index 388de3b8..1333a622 100644 --- a/cli/ValetPlus/AbstractDockerService.php +++ b/cli/ValetPlus/AbstractDockerService.php @@ -9,7 +9,7 @@ use Valet\CommandLine; use Valet\Filesystem; use function Valet\info; -use function Valet\output; +use function Valet\warning; /** * Docker container service. Please note that container names are restricted to the following characters [a-zA-Z0-9][a-zA-Z0-9_.-]. @@ -50,9 +50,7 @@ public function getAllRunningContainers(): Collection { $command = 'docker ps --format=\'{{.Names}}\''; $onError = function ($exitCode, $errorOutput) { - output($errorOutput); - - throw new DomainException('Docker was unable to check which containers are running.'); + warning($errorOutput); }; return collect(array_filter(explode(PHP_EOL, $this->cli->runAsUser($command, $onError)))); @@ -67,9 +65,13 @@ public function getAllRunningContainers(): Collection */ public function runCommand($command, $dir) { + $onError = function ($exitCode, $errorOutput) { + warning($errorOutput); + }; + $cwd = getcwd(); @chdir($dir); - $this->cli->runAsUser($command); + $this->cli->runAsUser($command, $onError); @chdir($cwd); return $this;