From 807b79e422dd9e8434bc38cc1dc49faf45fd42bb Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Wed, 13 Mar 2024 13:36:20 -0700 Subject: [PATCH 1/2] CLI-1292: Catch Cloud API type errors --- src/EventListener/ExceptionListener.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/EventListener/ExceptionListener.php b/src/EventListener/ExceptionListener.php index 9a6ffdd7d..53e3216da 100644 --- a/src/EventListener/ExceptionListener.php +++ b/src/EventListener/ExceptionListener.php @@ -79,6 +79,10 @@ public function onConsoleError(ConsoleErrorEvent $event): void { } } + if ($error instanceof \TypeError && str_contains($error->getMessage(), 'AcquiaCloudApi\Response')) { + $newErrorMessage = 'Cloud API returned an unexpected data type; this could indicate a problem with your Cloud application.'; + } + $this->helpMessages[] = "You can find Acquia CLI documentation at https://docs.acquia.com/acquia-cli/"; $this->writeUpdateHelp($event); $this->writeSupportTicketHelp($event); From 6ef589d135ab7e2ac5003935975adb62a5dbee5f Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Thu, 14 Mar 2024 08:39:56 -0700 Subject: [PATCH 2/2] fix message and add tests --- .phpstorm.meta.php | 6 +++++- src/EventListener/ExceptionListener.php | 2 +- .../Application/ExceptionApplicationTest.php | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php index 23883cf97..3a02d6a2a 100644 --- a/.phpstorm.meta.php +++ b/.phpstorm.meta.php @@ -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; @@ -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 ])); } diff --git a/src/EventListener/ExceptionListener.php b/src/EventListener/ExceptionListener.php index 53e3216da..ead38e639 100644 --- a/src/EventListener/ExceptionListener.php +++ b/src/EventListener/ExceptionListener.php @@ -80,7 +80,7 @@ public function onConsoleError(ConsoleErrorEvent $event): void { } if ($error instanceof \TypeError && str_contains($error->getMessage(), 'AcquiaCloudApi\Response')) { - $newErrorMessage = 'Cloud API returned an unexpected data type; this could indicate a problem with your Cloud application.'; + $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/"; diff --git a/tests/phpunit/src/Application/ExceptionApplicationTest.php b/tests/phpunit/src/Application/ExceptionApplicationTest.php index c79061ef1..90c69b982 100644 --- a/tests/phpunit/src/Application/ExceptionApplicationTest.php +++ b/tests/phpunit/src/Application/ExceptionApplicationTest.php @@ -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); + } + }