Skip to content

Commit

Permalink
CLI-1292: Catch Cloud API type errors (#1701)
Browse files Browse the repository at this point in the history
* CLI-1292: Catch Cloud API type errors

* fix message and add tests
  • Loading branch information
danepowell authored Mar 20, 2024
1 parent ec62a12 commit 82e821a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use AcquiaCloudApi\Response\AccountResponse;
use AcquiaCloudApi\Response\ApplicationResponse;
use AcquiaCloudApi\Response\ApplicationsResponse;
use AcquiaCloudApi\Response\CronResponse;
use AcquiaCloudApi\Response\CronsResponse;
use AcquiaCloudApi\Response\DatabasesResponse;
use AcquiaCloudApi\Response\EnvironmentResponse;
use AcquiaCloudApi\Response\EnvironmentsResponse;
Expand All @@ -14,7 +16,9 @@
'getApplicationByUuid' => ApplicationResponse::class,
'getApplicationEnvironments' => EnvironmentsResponse::class,
'getEnvironmentsDatabases' => DatabasesResponse::class,
'getEnvironment' => EnvironmentResponse::class
'getEnvironment' => EnvironmentResponse::class,
'getCron' => CronResponse::class,
'getCronJobsByEnvironmentId' => CronsResponse::class
]));

}
4 changes: 4 additions & 0 deletions src/EventListener/ExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public function onConsoleError(ConsoleErrorEvent $event): void {
}
}

if ($error instanceof \TypeError && str_contains($error->getMessage(), 'AcquiaCloudApi\Response')) {
$newErrorMessage = 'Cloud Platform API returned an unexpected data type. This is not an issue with Acquia CLI but could indicate a problem with your Cloud Platform application.';
}

$this->helpMessages[] = "You can find Acquia CLI documentation at https://docs.acquia.com/acquia-cli/";
$this->writeUpdateHelp($event);
$this->writeSupportTicketHelp($event);
Expand Down
17 changes: 17 additions & 0 deletions tests/phpunit/src/Application/ExceptionApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,21 @@ public function testInvalidApplicationUuid(): void {
self::assertStringContainsString('An alias consists of an application name', $buffer);
}

/**
* @group serial
*/
public function testApiTypeError(): void {
$tamper = function ($response): void {
$response[0]->server = [];
};
$this->mockRequest('getCronJobsByEnvironmentId', '24-a47ac10b-58cc-4372-a567-0e02b2c3d470', NULL, NULL, $tamper);
$this->setInput([
'command' => 'env:cron-copy',
'dest_env' => '24-a47ac10b-58cc-4372-a567-0e02b2c3d471',
'source_env' => '24-a47ac10b-58cc-4372-a567-0e02b2c3d470',
]);
$buffer = $this->runApp();
self::assertStringContainsString('Cloud Platform API returned an unexpected data type.', $buffer);
}

}

0 comments on commit 82e821a

Please sign in to comment.