From 9f54b098c61c2636b17d21100b6fbb64eb8a5d0c Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Tue, 26 Nov 2024 11:27:28 -0800 Subject: [PATCH] CLI-1417: TypeError when applications are not provisioned (#1835) --- src/Command/CommandBase.php | 4 ++-- src/Command/Push/PushArtifactCommand.php | 7 ++++++- src/Command/Ssh/SshKeyCommandBase.php | 7 ++++--- src/EventListener/ExceptionListener.php | 3 +++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Command/CommandBase.php b/src/Command/CommandBase.php index 68e719fa4..43c9982a1 100644 --- a/src/Command/CommandBase.php +++ b/src/Command/CommandBase.php @@ -1801,12 +1801,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 b340b31a2..d9e667fee 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; } }