Skip to content

Commit ee47ac5

Browse files
authored
MCLOUD-6221: Add specific error code in some steps (magento#760)
1 parent e213114 commit ee47ac5

28 files changed

+300
-41
lines changed

config/schema.error.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,12 @@
571571
stage: deploy
572572
step: 'install-update:split-db'
573573
type: warning
574+
!php/const Magento\MagentoCloud\App\Error::WARN_COPY_MOUNTED_DIRS_FAILED:
575+
title: 'Failed to restore some data generated during the build phase to the mounted directories'
576+
stage: deploy
577+
suggestion: 'Check the `cloud.log` for more information.'
578+
step: 'pre-deploy:restore-writable-dirs'
579+
type: warning
574580
!php/const Magento\MagentoCloud\App\Error::WARN_DEBUG_LOG_ENABLED:
575581
title: 'Debug logging is enabled in Magento'
576582
suggestion: 'To save disk space, do not enable debug logging for your production environments.'
@@ -587,6 +593,11 @@
587593
stage: post-deploy
588594
step: warm-up
589595
type: warning
596+
!php/const Magento\MagentoCloud\App\Error::WARN_CREATE_CONFIG_BACKUP_FAILED:
597+
title: 'Cannot create backup files'
598+
stage: post-deploy
599+
step: backup
600+
type: warning
590601
!php/const Magento\MagentoCloud\App\Error::WARN_CANNOT_GET_PROC_COUNT:
591602
title: 'Can not get system processor count:'
592603
type: warning

dist/error-codes.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ Warning errors indicate a problem with the Magento Commerce Cloud project config
147147
| 2023 | install-update:split-db | Enabling a split database will be skipped. | |
148148
| 2024 | install-update:split-db | The SPLIT_DB variable is missing the configuration for split connection types. | |
149149
| 2025 | install-update:split-db | Slave connection not set. | |
150+
| 2026 | pre-deploy:restore-writable-dirs | Failed to restore some data generated data during the build phase to the mounted directories. | Check the `cloud.log` for more information. |
150151

151152
### Post-deploy stage
152153

@@ -156,6 +157,7 @@ Warning errors indicate a problem with the Magento Commerce Cloud project config
156157
| 3001 | validate-config | Debug logging is enabled in Magento | To save disk space, do not enable debug logging for your production environments. |
157158
| 3002 | warm-up | Can not fetch store urls | |
158159
| 3003 | warm-up | Can not fetch store url | |
160+
| 3004 | backup | Cannot create backup files | |
159161

160162
### General
161163

@@ -177,4 +179,4 @@ table.error-table td:nth-child(1) {
177179
table.error-table td:nth-child(2) {
178180
width: 200px;
179181
}
180-
</style>
182+
</style>

src/App/Error.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,15 @@ class Error
129129
public const WARN_SPLIT_DB_ENABLING_SKIPPED = 2023;
130130
public const WARN_NOT_ENOUGH_DATA_SPLIT_DB_VAR = 2024;
131131
public const WARN_SLAVE_CONNECTION_NOT_SET = 2025;
132+
public const WARN_COPY_MOUNTED_DIRS_FAILED = 2026;
132133

133134
/**
134135
* Post-deploy
135136
*/
136137
public const WARN_DEBUG_LOG_ENABLED = 3001;
137138
public const WARN_CANNOT_FETCH_STORE_URLS = 3002;
138139
public const WARN_CANNOT_FETCH_STORE_URL = 3003;
140+
public const WARN_CREATE_CONFIG_BACKUP_FAILED = 3004;
139141

140142
/**
141143
* General

src/Filesystem/DirectoryCopier/CopyStrategy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function copy(string $fromDirectory, string $toDirectory): bool
4343
{
4444
if (!$this->file->isExists($fromDirectory)) {
4545
throw new FileSystemException(
46-
sprintf('Can\'t copy directory %s. Directory does not exist.', $fromDirectory)
46+
sprintf('Cannot copy directory %s. Directory does not exist.', $fromDirectory)
4747
);
4848
}
4949

src/Filesystem/DirectoryCopier/CopySubFolderStrategy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function copy(string $fromDirectory, string $toDirectory): bool
4848
{
4949
if (!$this->file->isExists($fromDirectory)) {
5050
throw new FileSystemException(
51-
sprintf('Can\'t copy directory %s. Directory does not exist.', $fromDirectory)
51+
sprintf('Cannot copy directory %s. Directory does not exist.', $fromDirectory)
5252
);
5353
}
5454

src/Filesystem/DirectoryCopier/SubSymlinkStrategy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function copy(string $fromDirectory, string $toDirectory): bool
5252

5353
if ($fromDirectory === false || !$this->file->isExists($fromDirectory)) {
5454
throw new FileSystemException(
55-
sprintf('Can\'t copy directory "%s". Directory does not exist.', $fromDirectory)
55+
sprintf('Cannot copy directory "%s". Directory does not exist.', $fromDirectory)
5656
);
5757
}
5858

src/Filesystem/DirectoryCopier/SymlinkStrategy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function copy(string $fromDirectory, string $toDirectory): bool
4949

5050
if (!$this->file->isExists($fromDirectory)) {
5151
throw new FileSystemException(
52-
sprintf('Can\'t copy directory %s. Directory does not exist.', $fromDirectory)
52+
sprintf('Cannot copy directory %s. Directory does not exist.', $fromDirectory)
5353
);
5454
}
5555

src/Filesystem/RecoverableDirectoryList.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77

88
namespace Magento\MagentoCloud\Filesystem;
99

10+
use Magento\MagentoCloud\Config\ConfigException;
1011
use Magento\MagentoCloud\Config\Environment;
1112
use Magento\MagentoCloud\Config\GlobalSection;
1213
use Magento\MagentoCloud\Config\Stage\DeployInterface;
1314
use Magento\MagentoCloud\Filesystem\DirectoryCopier\StrategyInterface;
15+
use Magento\MagentoCloud\Filesystem\Flag\ConfigurationMismatchException;
1416
use Magento\MagentoCloud\Filesystem\Flag\Manager as FlagManager;
1517
use Magento\MagentoCloud\Package\MagentoVersion;
18+
use Magento\MagentoCloud\Package\UndefinedPackageException;
1619

1720
/**
1821
* Returns list of recoverable directories
@@ -81,6 +84,10 @@ public function __construct(
8184
* Returns list of recoverable directories with recover strategy types.
8285
*
8386
* @return array
87+
*
88+
* @throws ConfigException
89+
* @throws ConfigurationMismatchException
90+
* @throws UndefinedPackageException
8491
*/
8592
public function getList(): array
8693
{

src/Step/Deploy/InstallUpdate/ConfigUpdate/Amqp.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
namespace Magento\MagentoCloud\Step\Deploy\InstallUpdate\ConfigUpdate;
99

10+
use Magento\MagentoCloud\App\Error;
1011
use Magento\MagentoCloud\App\GenericException;
12+
use Magento\MagentoCloud\Filesystem\FileSystemException;
1113
use Magento\MagentoCloud\Step\StepException;
1214
use Magento\MagentoCloud\Step\StepInterface;
1315
use Magento\MagentoCloud\Config\Magento\Env\ReaderInterface as ConfigReader;
@@ -74,7 +76,11 @@ public function execute()
7476
try {
7577
$config = $this->configReader->read();
7678
$amqpConfig = $this->amqpConfig->get();
79+
} catch (GenericException $e) {
80+
throw new StepException($e->getMessage(), $e->getCode(), $e);
81+
}
7782

83+
try {
7884
if (count($amqpConfig)) {
7985
$this->logger->info('Updating env.php AMQP configuration.');
8086
$config['queue'] = $amqpConfig;
@@ -84,8 +90,8 @@ public function execute()
8490
unset($config['queue']);
8591
$this->configWriter->create($config);
8692
}
87-
} catch (GenericException $e) {
88-
throw new StepException($e->getMessage(), $e->getCode(), $e);
93+
} catch (FileSystemException $e) {
94+
throw new StepException($e->getMessage(), Error::DEPLOY_ENV_PHP_IS_NOT_WRITABLE, $e);
8995
}
9096
}
9197
}

src/Step/Deploy/InstallUpdate/ConfigUpdate/CronConsumersRunner.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
namespace Magento\MagentoCloud\Step\Deploy\InstallUpdate\ConfigUpdate;
99

10+
use Magento\MagentoCloud\App\Error;
1011
use Magento\MagentoCloud\App\GenericException;
1112
use Magento\MagentoCloud\Config\Environment;
1213
use Magento\MagentoCloud\Config\Magento\Env\ReaderInterface as ConfigReader;
1314
use Magento\MagentoCloud\Config\Magento\Env\WriterInterface as ConfigWriter;
1415
use Magento\MagentoCloud\Config\RepositoryFactory;
1516
use Magento\MagentoCloud\Config\Stage\DeployInterface;
17+
use Magento\MagentoCloud\Filesystem\FileSystemException;
1618
use Magento\MagentoCloud\Package\MagentoVersion;
1719
use Magento\MagentoCloud\Step\StepException;
1820
use Magento\MagentoCloud\Step\StepInterface;
@@ -111,10 +113,14 @@ public function execute()
111113
'max_messages' => $runnerConfig->get('max_messages', static::DEFAULT_MAX_MESSAGES),
112114
'consumers' => $runnerConfig->get('consumers', []),
113115
];
114-
115-
$this->configWriter->create($config);
116116
} catch (GenericException $e) {
117117
throw new StepException($e->getMessage(), $e->getCode(), $e);
118118
}
119+
120+
try {
121+
$this->configWriter->create($config);
122+
} catch (FileSystemException $e) {
123+
throw new StepException($e->getMessage(), Error::DEPLOY_ENV_PHP_IS_NOT_WRITABLE, $e);
124+
}
119125
}
120126
}

0 commit comments

Comments
 (0)