From 02382ee5fa922cccea5dd85a36c2d2ed3de3285e Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 3 Aug 2022 11:01:03 +1000 Subject: [PATCH] gracefully fail when unable to locate expected binary on the system --- src/Illuminate/Foundation/Console/DocsCommand.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/Console/DocsCommand.php b/src/Illuminate/Foundation/Console/DocsCommand.php index 15dc49d6815f..b55fabfdbe7b 100644 --- a/src/Illuminate/Foundation/Console/DocsCommand.php +++ b/src/Illuminate/Foundation/Console/DocsCommand.php @@ -12,6 +12,7 @@ use Illuminate\Support\Str; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Process\Exception\ProcessFailedException; +use Symfony\Component\Process\ExecutableFinder; use Symfony\Component\Process\Process; use Throwable; @@ -385,13 +386,20 @@ protected function openViaCustomStrategy($url) * @param string $url * @return void */ + protected function openViaBuiltInStrategy($url) { - $process = tap(Process::fromShellCommandline(match ($this->systemOsFamily) { + $binary = (new ExecutableFinder())->find(match ($this->systemOsFamily) { 'Darwin' => 'open', 'Windows' => 'start', 'Linux' => 'xdg-open', - }.' '.escapeshellarg($url)))->run(); + }); + + if ($binary === null) { + $this->components->warn('Unable to open the URL on your system. You will need to open it yourself or create a custom opener for your system.'); + } + + $process = tap(Process::fromShellCommandline($binary.' '.escapeshellarg($url)))->run(); if (! $process->isSuccessful()) { throw new ProcessFailedException($process);