diff --git a/src/Command/CommandBase.php b/src/Command/CommandBase.php index 61918edbb..4ecf3a533 100644 --- a/src/Command/CommandBase.php +++ b/src/Command/CommandBase.php @@ -1802,12 +1802,12 @@ protected function getAnyProdAhEnvironment(string $cloudAppUuid): EnvironmentRes /** * Get the first VCS URL for a given Cloud application. */ - protected function getAnyVcsUrl(string $cloudAppUuid): string + protected function getAnyVcsUrl(string $cloudAppUuid): string|false { $environment = $this->getAnyAhEnvironment($cloudAppUuid, function (): bool { return true; }); - return $environment->vcs->url; + return $environment ? $environment->vcs->url : false; } protected function validateApplicationUuid(string $applicationUuidArgument): mixed diff --git a/src/Command/Push/PushArtifactCommand.php b/src/Command/Push/PushArtifactCommand.php index 389c42b05..e7b901a09 100644 --- a/src/Command/Push/PushArtifactCommand.php +++ b/src/Command/Push/PushArtifactCommand.php @@ -151,6 +151,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** * @return string[] + * @throws \Acquia\Cli\Exception\AcquiaCliException */ private function determineDestinationGitUrls(): array { @@ -165,7 +166,11 @@ private function determineDestinationGitUrls(): array } $applicationUuid = $this->determineCloudApplication(); - return [$this->getAnyVcsUrl($applicationUuid)]; + if ($vcsUrl = $this->getAnyVcsUrl($applicationUuid)) { + return [$vcsUrl]; + } + + throw new AcquiaCliException('No environments found for this application'); } /** diff --git a/src/Command/Ssh/SshKeyCommandBase.php b/src/Command/Ssh/SshKeyCommandBase.php index 27398b5d5..9fe47ca4a 100644 --- a/src/Command/Ssh/SshKeyCommandBase.php +++ b/src/Command/Ssh/SshKeyCommandBase.php @@ -199,9 +199,10 @@ private function checkPermissions(array $userPerms, string $cloudAppUuid, Output if (in_array($requiredPerm, $userPerms, true)) { switch ($requiredPerm) { case 'add ssh key to git': - $fullUrl = $this->getAnyVcsUrl($cloudAppUuid); - $urlParts = explode(':', $fullUrl); - $mappings['git']['ssh_target'] = $urlParts[0]; + if ($fullUrl = $this->getAnyVcsUrl($cloudAppUuid)) { + $urlParts = explode(':', $fullUrl); + $mappings['git']['ssh_target'] = $urlParts[0]; + } break; case 'add ssh key to non-prod': if ($nonProdEnv = $this->getAnyNonProdAhEnvironment($cloudAppUuid)) { diff --git a/src/EventListener/ExceptionListener.php b/src/EventListener/ExceptionListener.php index 07141fdab..d69994f78 100644 --- a/src/EventListener/ExceptionListener.php +++ b/src/EventListener/ExceptionListener.php @@ -79,6 +79,9 @@ public function onConsoleError(ConsoleErrorEvent $event): void case 'Database connection details missing': $this->helpMessages[] = 'Check that you have the \'View database connection details\' permission'; break; + case 'No environments found for this application': + $this->helpMessages[] = 'Check that the application has finished provisioning'; + break; } }