Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LOPS-1656] Handle ICR exceptions from backend. #2505

Draft
wants to merge 3 commits into
base: 3.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Change Log
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org)

## 3.2.3-dev

## 3.2.2 - 2023-09-28

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion config/constants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
---

# App
TERMINUS_VERSION: '3.2.2'
TERMINUS_VERSION: '3.2.3-dev'

# Connectivity
TERMINUS_HOST: 'terminus.pantheon.io'
Expand Down
9 changes: 8 additions & 1 deletion src/Commands/Branch/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Pantheon\Terminus\Commands\StructuredListTrait;
use Pantheon\Terminus\Site\SiteAwareInterface;
use Pantheon\Terminus\Site\SiteAwareTrait;
use Pantheon\Terminus\Exceptions\TerminusIcrSiteException;

/**
* Class ListCommand
Expand Down Expand Up @@ -37,6 +38,12 @@ class ListCommand extends TerminusCommand implements SiteAwareInterface
*/
public function listBranches($site_id)
{
return $this->getRowsOfFields($this->getSiteById($site_id)->getBranches());
try {
return $this->getRowsOfFields($this->getSiteById($site_id)->getBranches());
} catch (TerminusIcrSiteException $e) {
$this->log()->notice("This is an ICR site, branches are managed in the external VCS.");
$this->log()->debug($e->getMessage());
return;
}
}
}
5 changes: 5 additions & 0 deletions src/Commands/Connection/SetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Pantheon\Terminus\Site\SiteAwareInterface;
use Pantheon\Terminus\Site\SiteAwareTrait;
use Pantheon\Terminus\Exceptions\TerminusException;
use Pantheon\Terminus\Exceptions\TerminusIcrSiteException;

/**
* Class SetCommand.
Expand Down Expand Up @@ -64,6 +65,10 @@ public function connectionSet($site_env, $mode)
try {
$mode = strtolower($mode ?? '');
$workflow = $env->changeConnectionMode($mode);
} catch (TerminusIcrSiteException $e) {
$this->log()->debug($e->getMessage());
$this->log()->notice("This is an ICR site, connection mode switching is not currently supported.");
return;
} catch (TerminusException $e) {
$message = $e->getMessage();
if (strpos($message, $mode) !== false) {
Expand Down
11 changes: 11 additions & 0 deletions src/Exceptions/TerminusIcrSiteException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Pantheon\Terminus\Exceptions;

/**
* Class TerminusIcrSiteException
* @package Pantheon\Terminus\Exceptions
*/
class TerminusIcrSiteException extends TerminusException
{
}
8 changes: 7 additions & 1 deletion src/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use League\Container\ContainerAwareTrait;
use Pantheon\Terminus\Config\ConfigAwareTrait;
use Pantheon\Terminus\Exceptions\TerminusException;
use Pantheon\Terminus\Exceptions\TerminusIcrSiteException;
use Pantheon\Terminus\Helpers\LocalMachineHelper;
use Pantheon\Terminus\Session\SessionAwareInterface;
use Pantheon\Terminus\Session\SessionAwareTrait;
Expand Down Expand Up @@ -227,7 +228,7 @@ private function createRetryDecider(): callable
);
} else {
if (preg_match('/[2,4]0\d/', $response->getStatusCode())) {
// Do not retry on 20x and 40x responses.
// Do not retry on 20x or 40x responses.
return false;
}

Expand Down Expand Up @@ -427,6 +428,11 @@ public function request($path, array $options = []): RequestOperationResult
$this->logger->debug($jsonException->getMessage());
}

if ($response->getStatusCode() == 409 && $body == "icr_site") {
// This request is expected to fail for an ICR site, throw exception that will be catched down the road.
throw new TerminusIcrSiteException("This is an ICR site.");
}

return new RequestOperationResult([
'data' => $body,
'headers' => $response->getHeaders(),
Expand Down
Loading