diff --git a/src/Command/Environment/EnvironmentSshCommand.php b/src/Command/Environment/EnvironmentSshCommand.php index 3641b7b8c..58f8d1d74 100644 --- a/src/Command/Environment/EnvironmentSshCommand.php +++ b/src/Command/Environment/EnvironmentSshCommand.php @@ -48,24 +48,22 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $selection = $this->selector->getSelection($input, new SelectorConfig(chooseEnvFilter: SelectorConfig::filterEnvsMaybeActive())); - $environment = $selection->getEnvironment(); + try { + $selection = $this->selector->getSelection($input, new SelectorConfig(chooseEnvFilter: SelectorConfig::filterEnvsMaybeActive())); + $environment = $selection->getEnvironment(); - if ($input->getOption('all')) { - $output->writeln(array_values($environment->getSshUrls())); + if ($input->getOption('all')) { + $output->writeln(array_values($environment->getSshUrls())); - return 0; - } + return 0; + } - $container = $selection->getRemoteContainer(); + $container = $selection->getRemoteContainer(); - try { $sshUrl = $container->getSshUrl($input->getOption('instance')); } catch (EnvironmentStateException $e) { - if ($e->getEnvironment()->id !== $environment->id) { - throw $e; - } - switch ($e->getEnvironment()->status) { + $environment = $e->getEnvironment(); + switch ($environment->status) { case 'inactive': $this->stdErr->writeln(sprintf('The environment %s is inactive, so an SSH connection is not possible.', $this->api->getEnvironmentLabel($e->getEnvironment(), 'error'))); if (!$e->getEnvironment()->has_code) {