Skip to content

Commit

Permalink
CLI-1417: TypeError when applications are not provisioned (#1835)
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell authored Nov 26, 2024
1 parent 42c689f commit 9f54b09
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/Command/Push/PushArtifactCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

/**
* @return string[]
* @throws \Acquia\Cli\Exception\AcquiaCliException
*/
private function determineDestinationGitUrls(): array
{
Expand All @@ -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');
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/Command/Ssh/SshKeyCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
3 changes: 3 additions & 0 deletions src/EventListener/ExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 9f54b09

Please sign in to comment.