Skip to content

CLI-1778: success message immediately followed by a failure — confusing and misleading.#1988

Merged
deepakmishra2 merged 6 commits into
mainfrom
CLI-1778
Apr 29, 2026
Merged

CLI-1778: success message immediately followed by a failure — confusing and misleading.#1988
deepakmishra2 merged 6 commits into
mainfrom
CLI-1778

Conversation

@deepakmishra2
Copy link
Copy Markdown
Contributor

This pull request improves error handling and user feedback in the database backup and pull process, and updates related tests for better reliability. The main changes ensure that missing backup download URLs are detected early, user messaging is clearer, and test assertions are more robust.

Error handling improvements:

  • Added a check to verify that the backup download URL exists before attempting to download, and throw an AcquiaCliException with a clear message if it is missing.

User feedback and messaging:

  • Refactored the backup wait logic to always display the "Database backup is ready!" message after a successful backup, regardless of how the callback is invoked.

Testing improvements:

  • Updated the testPullDatabasesOnDemandFail test to use a try/catch block for more precise exception assertion, and added a check to ensure the success message is not shown when the backup fails.

Code cleanup:

  • Removed an unused import of React\EventLoop\Loop from PullCommandBase.php.

Copilot AI review requested due to automatic review settings April 28, 2026 10:20
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.42%. Comparing base (cdcce54) to head (348030e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #1988   +/-   ##
=========================================
  Coverage     92.42%   92.42%           
- Complexity     1956     1957    +1     
=========================================
  Files           123      123           
  Lines          7091     7091           
=========================================
  Hits           6554     6554           
  Misses          537      537           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@deepakmishra2 deepakmishra2 added the bug Something isn't working label Apr 28, 2026
@github-actions
Copy link
Copy Markdown

Try the dev build for this PR: https://acquia-cli.s3.amazonaws.com/build/pr/1988/acli.phar

curl -OL https://acquia-cli.s3.amazonaws.com/build/pr/1988/acli.phar
chmod +x acli.phar

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the pull database on-demand backup flow by preventing misleading success output on backup failure, adding an early guard for missing codebase backup download URLs, and tightening related PHPUnit assertions.

Changes:

  • Add an explicit check for a missing links.download.href in the codebase backup download path and throw an AcquiaCliException with a clearer message.
  • Refactor backup wait logic so “Database backup is ready!” is printed only after the notification completes successfully.
  • Update testPullDatabasesOnDemandFail to assert the exception and verify the success message is not printed when backup creation fails.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Command/Pull/PullCommandBase.php Improves backup wait messaging and adds early validation for codebase backup download URL.
tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php Makes failure test assertions more precise and verifies no success message appears on failure.
Comments suppressed due to low confidence (1)

src/Command/Pull/PullCommandBase.php:270

  • In the codebase UUID download path, $url is never updated via the on_stats callback (that callback only runs on $acquiaCloudClient->stream()), but the RequestException handler later assumes $url is a non-null UriInterface (e.g., calls $url->getHost()). If the codebase download triggers an SSL-related curl errno (51/60), this can cause a fatal error while handling the exception. Consider initializing a UriInterface from the download URL (or otherwise ensuring the SSL-fallback logic doesn't depend on $url being set) before calling the HTTP client request.
                if (!isset($backupResponse->links->download->href)) {
                    throw new AcquiaCliException('Cloud API failed to provide a valid backup download URL. The backup may have failed on the server.');
                }
                $downloadUrl = $backupResponse->links->download->href;
                $this->httpClient->request('GET', $downloadUrl, [
                    'progress' => static function (mixed $totalBytes, mixed $downloadedBytes) use (&$progress, $output): void {
                        self::displayDownloadProgress($totalBytes, $downloadedBytes, $progress, $output);
                    },
                    'sink' => $localFilepath,
                ]);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Command/Pull/PullCommandBase.php
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php Outdated
$this->output->writeln('<info>Database backup is ready!</info>');
};
$success = $this->waitForNotificationToComplete($acquiaCloudClient, $notificationUuid, $spinnerMessage, $successCallback);
Loop::run();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deepakmishra2 Why did we remove Loop::run(). How will now loop run if db update takes more time ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code in PullCommandBase had two calls that started the event loop:

  1. LoopHelper::getLoopy(...) — which internally calls Loop::run() at line 62. This is the blocking poll loop that checks the Cloud API notification status every 5 seconds (with a 45-minute watchdog timeout).
  2. Loop::run() — called again right after getLoopy() returned in PullCommandBase.

The second Loop::run() was redundant. By the time getLoopy() returns, the event loop has already run to completion — all timers were cancelled inside cancelTimers(), so the loop had no more work and exited. Calling Loop::run() again just immediately returned with nothing to do.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoopHelper::getLoopy() still handles the entire polling lifecycle internally via Loop::run() on line 62. If the backup takes a long time, it will keep polling every 5 seconds up to the 45-minute timeout, same as before.

if (!$success) {
throw new AcquiaCliException('Cloud API failed to create a backup');
}
$this->output->writeln('');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deepakmishra2 Removing Loop::run() is Ok, but we should remove this and instead use the callback function which was there earlier, instead of empty callback.

Copy link
Copy Markdown
Contributor Author

@deepakmishra2 deepakmishra2 Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh actually it was left intentionally because to provide a blank line after the spinner finishes. This was also there earlier on line 399

@anujkaushal
Copy link
Copy Markdown

worked for me..

~/project $ ~/acli_dump/acli.phar pull:db <REDACTED> --on-demand
    ⌛ Creating an on-demand database(s) backup on Cloud Platform...

    ✔ Creating an on-demand database(s) backup on Cloud Platform
    ✔ Waiting for database backup to complete...
    ✔ Downloading <REDACTED> database copy from the Cloud Platform
    ✔ Importing <REDACTED> database download
~/project $ ~/acli_dump/acli.phar pull:db <REDACTED>
                                                                                                              
 [INFO] Using a database backup that is 0 hours old. Backup #<REDACTED> was created at Wed <REDACTED> 13:19:22 UTC 2026.
        You can view your backups here: https://cloud.acquia.com/a/environments/<REDACTED>/databases
        To generate a new backup, re-run this command with the --on-demand option.

    ✔ Downloading <REDACTED> database copy from the Cloud Platform
    ✔ Importing <REDACTED> database download

@deepakmishra2 deepakmishra2 enabled auto-merge (squash) April 29, 2026 15:21
@deepakmishra2 deepakmishra2 dismissed vishalkhode1’s stale review April 29, 2026 15:29

Requested review again

@deepakmishra2 deepakmishra2 merged commit 75a1e70 into main Apr 29, 2026
26 checks passed
@deepakmishra2 deepakmishra2 deleted the CLI-1778 branch April 29, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants